loadImage method
void
loadImage()
Implementation
void loadImage() {
imageEventDispatcher.handleOnLoadStart();
var src = curSrc;
if (src == null) {
imageEventDispatcher.handleOnError();
imageEventDispatcher.handleOnLoadEnd();
return;
} else {
dispatchedEvent = {};
ImageProvider? imageProvider;
try {
imageProvider = getImage(src);
} catch (e) {
LogUtils.e('loadImage', 'getImage fail, url: $src, error: ${e.toString()}');
imageEventDispatcher.handleOnError();
imageEventDispatcher.handleOnLoadEnd();
}
imageProvider?.resolve(const ImageConfiguration()).addListener(
ImageStreamListener(
(image, flag) {
if (isDispose) return;
if (!dispatchedEvent.contains(NodeProps.kOnLoad) && src == curSrc) {
imageEventDispatcher.handleOnLoad();
imageEventDispatcher.handleOnLoadEnd();
imageWidth = image.image.width;
imageHeight = image.image.height;
dispatchedEvent.add(NodeProps.kOnLoad);
dispatchedEvent.add(NodeProps.kOnLoadEnd);
LogUtils.dWidget("ID:$id, node:$idDesc, image load success, info:${image.toString()}");
notifyListeners();
}
},
onChunk: (event) {
if (isDispose) return;
var total = event.expectedTotalBytes;
var loaded = event.cumulativeBytesLoaded;
if (loaded > 0 && total is int && total > 0) {
var params = VoltronMap();
params.push('loaded', loaded);
params.push('total', total);
imageEventDispatcher.handleOnProgress(params);
}
},
onError: (exception, stackTrace) {
if (isDispose) return;
if (src == curSrc) {
imageEventDispatcher.handleOnError();
imageEventDispatcher.handleOnLoadEnd();
LogUtils.dWidget("ID:$id, node:$idDesc, image load error, src:$src, exception:${exception.toString()}");
notifyListeners();
}
},
),
);
image = imageProvider;
}
}