I often need to know if the image is still loading or has successfully loaded yet.
Can you please add a callback or notification for the loading state.
I added two callback, and tested in my project. Hope that helps
Would love to see this merged! Exactly what I need, because images may not be available for a long time I want to hide the whole widget when it fails to load an image. This would make it possible.
Now working with the builders
How is the builders going to notify when the image is loaded. Placeholder builder called when start loading, error widget builder called when image loaded failed.
@RyanYANG52 If you set the imageBuilder with a simple Image yourself you also get a callback on loaded.
OK, thanks.
@renefloor We need a tutorial or a section in the README cause i doubt most of us know how you do it ...
Actually i figure it out. Posting code here for others.
final VoidCallback onLoaded;
...
CachedNetworkImage(
imageUrl: "http://via.placeholder.com/200x150",
imageBuilder: (context, imageProvider) {
if (onLoaded != null) {
onLoaded();
}
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
colorFilter: ColorFilter.mode(Colors.red, BlendMode.colorBurn)),
),
);
},
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
);
This is way too complicated and too much unnecessary code in my opinion. Why do I have to write the complete imageBuilder myself just because I want to know when the image is loaded @renefloor ? What's wrong with adding a simple onLoadedCallback or at least calling the progressIndicatorBuilder again with progress = 1.0 in every case when the loading is done?
The answer from @kwent works but clean and clear code looks different to me.
Most helpful comment
I added two callback, and tested in my project. Hope that helps
97