fetchToMemory method

Future<Uri> fetchToMemory(
  1. String fileName
)

Implementation

Future<Uri> fetchToMemory(String fileName) async {
  if (kIsWeb) {
    final uri = _sanitizeURLForWeb(fileName);
    // We rely on browser caching here. Once the browser downloads this file,
    // the native side implementation should be able to access it from cache.
    await http.get(uri);
    return uri;
  }

  // read local asset from rootBundle
  //final byteData = await rootBundle.load('$prefix$fileName');
    final byteData = File(fileName).readAsBytesSync();

  // create a temporary file on the device to be read by the native side
  final file = File(fileName);
  await file.create(recursive: true);
  await file.writeAsBytes(byteData.buffer.asUint8List());

  // returns the local file uri
  return file.uri;
}