Mahi
Mahi

Reputation: 6292

Do we need to explicitly implement ImageCache if we are using ImagePicker library in flutter?

I am actually trying to implement ImageCache concept when using ImagePicker library, but before implementing this I just want to know if the ImageCache is handled internally by flutter as I've seen logs in my app which says ImageCache.putIfAbsent when I was using NetworkImage.

Please can someone confirm if this is done implicitly or do we need to handle this explicitly.

Many Thanks, Mahi

Upvotes: 1

Views: 474

Answers (3)

Mahi
Mahi

Reputation: 6292

I've actually used this package cached_network_image 0.2.1 which internally uses shared preferences instead of reimplementing the image cache, i hope this helps someone who is looking for this kind of functionality.

regards, Mahi

Upvotes: 0

Hemanth Raj
Hemanth Raj

Reputation: 34829

Yes, flutter internally manages image cache which is already implemented by ImageProvider and its sub classes such as AssetBundleImageProvider, FileImage, MemoryImage & NetworkImage. Flutter caches upto 1000 images(as mentioned in docs).

ImagePicker is a plugin that launches a native application to choose an image from. Thus all images show when picking would be handled by the Gallery app or what so ever.

So, If you are using ImagePicker plugin to pick image and Image.file to show images on UI and trying to cache them, then no need of implementing ImageCache, because Image.file uses FileImage which already has image cache implemented.

To read more on ImageCache, take look at docs here.

Hope that helped!

Upvotes: 3

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657937

There us a default image cache used. You can implement your own to get custom behavior, but you can just rely on the default.

Upvotes: 0

Related Questions