storeImage function

Future<File?> storeImage(
  1. Uint8List imgBytes,
  2. String name
)

stores the imgBytes as an image given by the name, returns the new File

Implementation

Future<File?> storeImage(Uint8List imgBytes, String name) async {
  // Write the file
  try {
    var file = await localFile(name);
    await file.parent.create(recursive: true);
    // Avoid rewriting already valid cached files (prevents duplicate "Stored image at ..."
    // logs and reduces UI-triggered redundant writes).
    if (file.existsSync()) {
      try {
        if (file.lengthSync() >= 5) return file;
      } catch (_) {}
    }
    file = await file.writeAsBytes(imgBytes); //u good?
    debugPrint('Stored image at ${file.path}');
    return file;
  } catch (e) {
    debugPrint("!!! failed to store image: " + e.toString());
    return null;
  }
}