imageFromBytes function Assets and loading
Decodes an encoded image (PNG, JPEG, etc.) from raw bytes.
Uses dart:ui's built-in image codecs. Throws if the bytes can't be
decoded as an image.
Implementation
Future<ui.Image> imageFromBytes(Uint8List bytes) async {
final buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
final codec = await ui.instantiateImageCodecFromBuffer(buffer);
final frame = await codec.getNextFrame();
return frame.image;
}