createUIImageFromImageAsset static method
Creates an Image object from a raster image asset.
This method loads an image from the provided imageAsset path and
resizes it to the specified height and width.
imageAsset: The asset path of the image to be loaded.height: The target height of the image. Defaults to50.width: The target width of the image. Defaults to50.
Implementation
static Future<Image> createUIImageFromImageAsset(
String imageAsset, {
int height = 50,
int width = 50,
}) async {
final ByteData assetImageByteData = await rootBundle.load(imageAsset);
final codec = await instantiateImageCodec(
assetImageByteData.buffer.asUint8List(),
targetHeight: height,
targetWidth: width,
);
final frameInfo = await codec.getNextFrame();
return frameInfo.image;
}