createImage method

Future<File> createImage(
  1. String name,
  2. String imagePath
)

Creates and returns a local image File according to the given name and imagePath.

Implementation

Future<File> createImage(String name, String imagePath) async {
  final directory = await getApplicationDocumentsDirectory();
  final file = File('${directory.path}/$name');

  final imageData = await rootBundle.load(imagePath);
  final bytes = imageData.buffer
      .asUint8List(imageData.offsetInBytes, imageData.lengthInBytes);

  file.writeAsBytesSync(bytes);

  return file;
}