I am working on an app, which displays lots of images from the local storage to the user and I wonder what the best caching strategy would be.
I am using FileImage
as the ImageProvier
. Since I am displaying the same Image, at different places I fear that using FileImage
multiple time would load the image multiple times unnecessarily.
On the other Hand, if I add a caching layer, I fear that I might run out of memory.
So my questions:
FileImage
cache the image? Or does it reload if I call it again?If you want full control, I would recommend using this flutter_cache_manager 3.1.2.
There is a method called get getFileFromCache
.
It only retrieves from cache and returns no file when the file is not in the cache.
Before making a decision though, I would highly recommend you run your application on a physical device in profile mode to analyse your performance first, that should give you a timeline and memory snapshots that you can dig into and see what Flutter is doing with your images and how much resources it is currently taking. Check this link to the official dev docs, in short don't fix what's not broken.