saveImage static method

Future<File?> saveImage(
  1. Image image,
  2. String path
)

Implementation

static Future<File?> saveImage(Image image, String path) async {
  try {
    final byteData = await image.toByteData(format: ImageByteFormat.png);

    if (byteData == null) {
      throw Exception("Failed to convert image to bytes");
    }

    final pngBytes = byteData.buffer.asUint8List();

    return await File(path).writeAsBytes(pngBytes);
  } catch (err) {
    debugPrint("saveImage error : $err");
    return null;
  }
}