assetToExternalStorage method

Future<File> assetToExternalStorage(
  1. String filename
)

Implementation

Future<File> assetToExternalStorage(String filename) async {
  ByteData byteData = await rootBundle.load('assets/$filename');
  // this creates the file image
  Directory appDir = await getApplicationDocumentsDirectory();
  var _path = appDir.path + '/www';
  File file = await File('$_path/$filename').create(recursive: true);
  // copies data byte by byte
  await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
  return file;
}