getImageFileFromAssets function

Future<File> getImageFileFromAssets(
  1. String path
)

Implementation

Future<File> getImageFileFromAssets(String path) async {
  final byteData = await rootBundle.load(path);

  final file = File('${(await getTemporaryDirectory()).path}/$path');
  bool exist = await file.exists();
  if (!exist) {
    await file.create(recursive: true);
  }

  await file.writeAsBytes(byteData.buffer
      .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

  return file;
}