Paulonia Cache Image (with null safety)

codecov License: MIT

Null safety: This package supports Null safety but due to an error the null-safety badge is not placed (Explanation).

Flutter package for download and store images in cache. It supports in-memory and storage cache in Android, iOS and Web for network and Google Cloud Storage images.



To use this package add paulonia_cache_image as a dependency in your pubspec.yaml file.

You have to initialize the package in your main() function:

void main() async{
  await PCacheImage.init();

In the init() function you can initialize the default values of the Properties of ImageProvider. You can change a value in all Paulonia cache image widgets in your app.

Paulonia cache image extends ImageProvider, so you can use it with any widget that supports an ImageProvider only with the URL. By default, the image is cached in the platform storage:

  image: PCacheImage('')
  image: PCacheImage(

In-memory cache

With the default image cache in the platform storage there is a problem: when you make a setState() the package reads the storage and retrieve the image, this process causes the image to flicker!. With in-memory cache, this process is more quickly and there is no flicker. You can enable it as follows:

  image: PCacheImage('', enableInMemory: true)

You can enable in-memory cache in all PCacheImage widgets in the init() function:

void main() async{
  await PCacheImage.init(enableInMemory: true);

Use only where your require. The problem with this approach is the memory usage increase. We recommend use only with images in widgets that run setState(), to erase the flicker. To avoid an uncontrollable memory growth you can set the maximum number of images that to be stored in memory:

void main() async{
  await PCacheImage.init(enableInMemory: true, maxInMemoryImages: 5);

This functionality works as a queue, to save a new image to memory, the oldest one is deleted.

Clear Entire Cache

There could be situations where you might want to clear the whole cache may be to rebuild the cache again. Calling the following method will empty the cache.

await PCacheImage.clearAllCacheImages();

CORS on web

On the web when you try to make a request and download an image, it can throw an error with the CORS. Depends on the image type there is a solution:

Google Storage Images

You must to enable CORS in your bucket

Network Images

You can set a proxy in the init() function:

void main() async{
  await PCacheImage.init(proxy: "");

The proxy property is only used with network image in the way: "".


PCacheImage has the follow properties:

PropertyWhat does it doDefault
enableInMemoryEnable or disable the in-memory cachefalse
enableCacheEnable or disable the cachetrue
retryDurationIf the download fails, retry after this duration2s
maxRetryDurationMax accumulated time of retries10s
imageScaleThe image scale1.0
maxInMemoryImagesGlobal variable, sets a max number of images in memory7
clearCacheImageDeletes the image from cachefalse


This packaged was made by ChrisChV and is used in all Paulonia projects.