A Flutter utility that manages Firebase Storage download URLs and caches the results
Cached Firestorage exposes a Singleton
which you can access through CachedFirestorage.instance
The default cache duration
is of 360s
(6h
): you can customize this by passing the number of seconds to the instance:
CachedFirestorage.instance.cacheTimeout = 30;
You can, for code organization purposes, split the cache into subpaths. Those subpaths must be created at the beginning, by invoking
CachedFirestorage.instance.setStorageKeys({'cachePathName': 'cachePathValue'});
This is the main api: it's a Future<String>
. When it completes, it returns in its snapshot.data
the Firebase Storage's download url of the requested resource,
caching the result. Every time you will ask for it again, you'll have direct access to the resource's url.
getDownloadURL
always returns a String
, meaning that if no file is matched and no fallbackFilePath
(see below) is provided, it will return ''
;
String mapKey
: The key at which your cached entry will be storedString filePath
: The file path on your Firebase Storage bucketString? storageKey
: You can split the cache into sub-paths: this is the subpath keyString? fallbackFilePath
: If provided, this is the path at which Cached Firestorage will try to point in case of no matches on the first attempt on Firebase Storage. If the second attempt goes bad too, Cached Firestorage will return an empty string;
By calling this api you can remove a cache entry when you want. Very useful in case you need to update the download URL of a previously stored resource before the cache expires.
String mapKey
: the key to be removed from the cacheString? storageKey
: the storage key in which Cached Firestorage should search the mapKey
Since Firebase Storage is particularly useful when it's a matter of hosting pictures, CachedFirestorage ships with a built-in widget that you can use to display an image stored in your bucket.
String imagePath
: The file path on your Firebase Storage bucketString mapKey
: The key at which your cached entry will be storedbool useAvatarView = false
: If true, it will render your image as an AvatarViewString? storageKey
: You can split the cache into sub-paths: this is the subpath keyString? placeholder
: The file path of a local asset to use as placeholderdouble? avatarViewRadius
: The radius of the avatar (mandatory ifuseAvatarView == true
)BoxFit? fit
: Optional parameter to be passed to a non-avatar image (ignored ifuseAvatarView == true
)