getImageFileFromAssets method

Future<File> getImageFileFromAssets(
  1. String assetPath
)

Copies the asset at assetPath to the device's temporary directory and returns the resulting File.

The file is always written as temp_image.png in the temporary directory, so it will be overwritten on subsequent calls.

Implementation

Future<File> getImageFileFromAssets(String assetPath) async {
  final byteData = await rootBundle.load(assetPath);
  final dir = await getTemporaryDirectory();
  final file = File('${dir.path}/temp_image.png');
  await file.writeAsBytes(byteData.buffer.asUint8List());
  return file;
}