convertUiImageToString function

Future<String?> convertUiImageToString(
  1. Image image
)

This function converts a ui Image to a base 64 encoded string. The image parameter is a ui.Image, such as what the crop tool will give you after cropping an image. This is useful if you have to save the ui.Image to storage (such as with Hive)

Implementation

Future<String?> convertUiImageToString(ui.Image image) async {
  ByteData? data = await image.toByteData(format: ui.ImageByteFormat.png);
  if (data != null) {
    return base64Encode(Uint8List.view(data.buffer));
  } else {
    return null;
  }
}