loadImageFromAsset function
load an image from asset
Implementation
Future<Image> loadImageFromAsset(String fileName, {bool isAsset = true}) {
final c = Completer<Image>();
var futureData;
if (isAsset) {
futureData = rootBundle.load(fileName).then((data) => data.buffer.asUint8List());
} else {
futureData = File(fileName).readAsBytes();
}
futureData.then((data) {
instantiateImageCodec(data).then((codec) {
codec.getNextFrame().then((frameInfo) {
c.complete(frameInfo.image);
});
});
}).catchError((error) {
c.completeError(error);
});
return c.future;
}