getFileFromAssets method

Future<File> getFileFromAssets(
  1. String path
)

Implementation

Future<File> getFileFromAssets(String path) async {
  String tempPath = await getTemporaryDir('assets');
  var filePath = "$tempPath/$path";
  var file = File(filePath);
  if (file.existsSync()) {
    return file;
  } else {
    final byteData = await rootBundle.load(path);
    final buffer = byteData.buffer;
    await (await file.create(recursive: true))
        .writeAsBytes(buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
    return file;
  }
}