My App uses this plugin in order to display a scrollable list of images in a specific area.
There is, however, time between the download of the list and the actual display of an image, and some chance that the internet connection drops.
So I was looking for a method to pre-download the images and make sure they're in the right place for CacheNetworkImage to pick up.
A simple way could be to utilize CachedNetworkImage itself, but there was no ready method available. Here is a suggestion:
downloadImage(String url) async {
print("downloading $url");
var provider = CachedNetworkImageProvider(url);
var imageSub = StreamController<String>();
final stream = imageSub.stream;
provider.load(provider).addListener((image, yesNo) {
print("image?: $image");
if (image == null) {
imageSub.sink.addError(Error());
} else {
imageSub.sink.add(url);
}
imageSub.sink.close();
});
return stream.single.whenComplete(() {
imageSub?.close();
});
}
If this method is useful enough, I would be happy to prepare a PR for inclusion.
I am currently working on a seperation of the various functions of the cache_manager. I will keep in mind that this should be possible as well.
You can now access the CacheManager and already download the file if you want.
@renefloor Would you mind providing a quick example about how to do this?
@jasonlfunk did you find out?
Most helpful comment
I am currently working on a seperation of the various functions of the cache_manager. I will keep in mind that this should be possible as well.