saveImage method

Future<String> saveImage(
  1. int i
)

Saves the generated image to a file and returns the file path. i is the index of the image to save. Returns a Future that completes with the file path of the saved image.

Implementation

Future<String> saveImage(int i) async {
  var pngBytes = (await images[i].toByteData(format: ui.ImageByteFormat.png))!;
  // Use plugin [path_provider] to export image to storage
  io.Directory directory = await getTemporaryDirectory();
  String path = directory.path;
  print(path);
  await io.Directory('$path/$directoryName').create(recursive: true);
  var file = io.File('$path/$directoryName/temp$i.png');
  file.writeAsBytesSync(pngBytes.buffer.asInt8List());
  print(file.path);
  return file.path;
}