firebase_cached_image 0.4.5 icon indicating copy to clipboard operation
firebase_cached_image: ^0.4.5 copied to clipboard

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.

Firebase_Cached_Image #

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.

Set up #

Setup firebase (

Firebase Image Provider #

If you want to show image from your cloud storage then use Image Widget and pass FirebaseImageProvider as ImageProvider to image argument. In FirebaseImageProvider pass FirebaseUrl. FirebaseUrl is a class containing Google Storage Url String ex. FirebaseUrl(gs://bucket_f233/logo.jpg).

  image: FirebaseImageProvider(

You can alter default caching behaviour by passing CacheOptions to provider.

  image: FirebaseImageProvider(
    options: CacheOptions(
      // Source from image will be fetched 
      // Default [Source.cacheServer]
      source: Source.server,

By default it will first try to fetch the image from cache, if image exists then it will be returned otherwise image will be fetched from server and then cached.

If you want to always fetch latest image from server then pass Source.server to CacheOptions.source.

  source: Source.server,

If you want to fetch image from server only if it is updated after last fetched then set checkForMetadataChange to true.

  checkForMetadataChange: true,

By default image fetched from cache will be returned immediately and then server call will be made for checking if the file is updated and then latest image will be cached in background.If you want server call to be made first then set metadataRefreshInBackground to false.

options: CacheOptions(
  checkForMetadataChange: true,
  metadataRefreshInBackground: false,

Image updation is checked by fetching image's metadata from server then comparing to cached image's metadata.

Note: Metadata retrieval is a Class B operation in google cloud storage. you will be charged for that. Check pricing here ( .Google does offer 50,000 free Class B operations per month.

Firebase Cache Manager #

if you want to work with any type of cloud storage file and want more functionality then use FirebaseCacheManager.

Download and cache any file.

final file = await FirebaseCacheManager().getSingleFile(
print(file); // Cached file's path, can be used for sharing file

Download and cache file before use. Can be useful for caching frequently used image at app's load time.

await FirebaseCacheManager().preCache(

Refresh already cached file..

Checks if the file has been updated in server, then download the file if it has been updated and saves it to cache.

await FirebaseCacheManager().refreshCachedFile(

Delete specific file from cache.

await FirebaseCacheManager().delete(

Clear all the cache.

await FirebaseCacheManager().clearCache();

Use custom sub-directory to save files in desired directory in system's temporary directory

final manager = FirbaseCacheManager(subDir: "profile_pictures");

Also helpful in saving files in multiple folders

final profilePicturesCacheManager = FirbaseCacheManager(subDir: "profile_pictures");
final postsCacheManager = FirbaseCacheManager(subDir: "posts");

// Only delete files in posts directory
await postsCacheManger.clearCache();

No support for caching in web, everything will be downloaded from server.

pub points


unverified uploader

Cache Manager and Cached ImageProvider for Firebase Cloud Storage Objects.

Repository (GitHub)
View/report issues


API reference


Icon for licenses.MIT (LICENSE)


firebase_core, firebase_storage, flutter, path, path_provider, sqflite, uuid


Packages that depend on firebase_cached_image