fromAsset method

  1. @override
Future<ImageElement?> fromAsset(
  1. String asset, {
  2. String? package,
})
override

asset - path of the file to be loaded

package - if the file is from another flutter package add the name of the package here

Implementation

@override
Future<ImageElement?> fromAsset(String asset, {String? package}) async{
  asset = package != null?'packages/$package/${path+asset}':path+asset;
  final cacheName = asset;

  asset = manager.resolveURL(asset);
  final cached = Cache.get(cacheName);

  if (cached != null) {
    manager.itemStart(cacheName);
    manager.itemEnd(cacheName);
    return cached;
  }

  ImageElement? resp;
  if(!kIsWeb){
    final ByteData fileData = await rootBundle.load(asset);
    final bytes = fileData.buffer.asUint8List();
    resp = await processImage(bytes,asset,flipY);
  }
  else{
    resp = await processImage(null,asset,flipY);
  }

  Cache.add(cacheName,resp);
  return resp;
}