load static method
load image by asset path
Implementation
static Future<Image?> load({
/// asset path
required String assetPath,
/// crop image area
Rect? cropRect,
}) async {
if (!_cache.containsKey(assetPath)) {
final loader = ImageLoader._(assetPath);
final image = await loader._loadLibImage();
_cache[assetPath] = image;
}
final image = _cache[assetPath];
if (image == null) return null;
var rect = (cropRect == null)
? Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble())
: cropRect;
final crop = libImage.copyCrop(image, rect.left.toInt(), rect.top.toInt(),
rect.width.toInt(), rect.height.toInt());
final img = Image.memory(
Uint8List.fromList(libImage.encodePng(crop)),
width: crop.width.toDouble(),
height: crop.height.toDouble(),
);
return img;
}