createUIImageFromSvgAsset static method
Creates an Image object from an SVG asset.
This method loads an SVG from the provided svgAsset path and converts
it into a raster Image of the specified height and width.
svgAsset: The asset path of the SVG 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> createUIImageFromSvgAsset(
String svgAsset, {
int height = 50,
int width = 50,
}) async {
final PictureInfo pictureInfo =
await vg.loadPicture(SvgAssetLoader(svgAsset), null);
var pictureWidth = pictureInfo.size.width.toInt();
var pictureHeight = pictureInfo.size.height.toInt();
final Image image = await pictureInfo.picture.toImage(pictureWidth, pictureHeight);
pictureInfo.picture.dispose();
final resizedImage = await _resizeSvg(image, width, height, pictureWidth, pictureHeight);
return resizedImage ?? image;
}