Skip to content

The CachedFirestorage dart package official repo

License

Notifications You must be signed in to change notification settings

TheAppCrafter/cached_firestorage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cached Firestorage

pub license: MIT style: flutter_lints dart Github

A Flutter utility that manages Firebase Storage download URLs and caches the results

Usage

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'});

APIs

getDownloadURL

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 '';

Parameters (all named)

  • String mapKey: The key at which your cached entry will be stored
  • String filePath: The file path on your Firebase Storage bucket
  • String? storageKey: You can split the cache into sub-paths: this is the subpath key
  • String? 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;

removeCacheEntry

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.

Parameters (all named)

  • String mapKey: the key to be removed from the cache
  • String? storageKey: the storage key in which Cached Firestorage should search the mapKey

Widgets

RemotePicture

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.

Parameters (all named)

  • String imagePath: The file path on your Firebase Storage bucket
  • String mapKey: The key at which your cached entry will be stored
  • bool useAvatarView = false: If true, it will render your image as an AvatarView
  • String? storageKey: You can split the cache into sub-paths: this is the subpath key
  • String? placeholder: The file path of a local asset to use as placeholder
  • double? avatarViewRadius: The radius of the avatar (mandatory if useAvatarView == true)
  • BoxFit? fit: Optional parameter to be passed to a non-avatar image (ignored if useAvatarView == true)

About

The CachedFirestorage dart package official repo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 72.2%
  • Ruby 13.1%
  • Swift 7.9%
  • HTML 6.0%
  • Other 0.8%