Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter NetworkImage vs cached_network_image

Tags:

flutter

Flutter recommends to use cached_network_image here https://flutter.dev/docs/cookbook/images/cached-images. I used it and it worked fine. I tried NetworkImage and it worked, too.

I read from the doc that NetworkImage also caches the downloaded image locally. So what's the point in using cached_network_image instead of NetworkImage? Is there a comparison how their caching strategies differentiate from one another? Thanks!

like image 693
ArtS Avatar asked Dec 12 '20 03:12

ArtS


1 Answers

The difference is significant and really helpful too...as you know fetching image from network takes time so cached network image provides you options for space holder to show when loading and error widget when can't load which are not there in NetworkImage. As a developer, you must be ready for every situation so that's the reason for recommending cached network images.

UPDATE: ImageNetwork now has a loadingBuilder and errorbuilder parameters, so it too can now show a loading indicator similar to cached network image. But in CachedImageNetwork once the image is loaded it's cached in the system until the URL changes, which gives faster loading of the image every time and there are also many more features to explore please see official read me documents.

So still I prefer cachedNetworkImage until NetworkImage has similar features.

Hope you understand! Otherwise, let me know in the comments down below!

like image 137
Jagadish Avatar answered Oct 09 '22 18:10

Jagadish