loadImage method
Load image from disk cache first, if not found then load from network.
onComplete
is called when imageBytes
become available.
Implementation
void loadImage(VoidCallback onComplete) {
if (this.frames != null) {
this.state = LoadState.success;
onComplete();
}
final fileStream = DefaultCacheManager().getFileStream(this.url!,
headers: this.requestHeaders as Map<String, String>?);
fileStream.listen(
(FileResponse fileInfo) {
// the reason for this is that, when the cache manager fetches
// the image again from network, the provided `onComplete` should
// not be called again
if (this.frames != null) {
return;
}
this.state = LoadState.success;
/// todo fix
// PaintingBinding.instance!.instantiateImageCodec(fileInfo.originalUrl).then((codec) {
// this.frames = codec;
// onComplete();
// }, onError: (error) {
// this.state = LoadState.failure;
// onComplete();
// });
},
onError: (error) {
this.state = LoadState.failure;
onComplete();
},
);
}