decodeImage method
Decodes an image from the specified file into a ui.Image object.
This method reads the file as bytes and then decodes the bytes into a Flutter ui.Image object. It uses a Completer to handle the asynchronous decoding process.
Parameters:
file: A File object representing the image file to decode.
Returns: A Future<ui.Image> that resolves to the decoded image.
Implementation
Future<ui.Image> decodeImage(File file) async {
final Uint8List bytes = await file.readAsBytes();
final Completer<ui.Image> completer = Completer();
ui.decodeImageFromList(bytes, (ui.Image img) {
completer.complete(img);
});
return completer.future;
}