createUIImageFromImageAsset static method

Future<Image> createUIImageFromImageAsset(
  1. String imageAsset, {
  2. int height = 50,
  3. int width = 50,
})

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 to 50.
  • width: The target width of the image. Defaults to 50.

Returns a Future that completes with the loaded Image.

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;
}