DynamicCachedFonts.fromFirebase constructor

DynamicCachedFonts.fromFirebase({
  1. required String bucketUrl,
  2. required String fontFamily,
  3. int maxCacheObjects = kDefaultMaxCacheObjects,
  4. Duration cacheStalePeriod = kDefaultCacheStalePeriod,
})

Allows dynamically loading fonts from firebase storage with the given firebase storage url, and caching them.

Firebase app must be initialized before loading the font!!

  • REQUIRED The bucketUrl property is used to specify the download url for the required font. It should be a valid Google Cloud Storage (gs://) url which points to a font file. Currently, only OpenType (OTF) and TrueType (TTF) fonts are supported.

  • REQUIRED The fontFamily property is used to specify the name of the font family which is to be used as TextStyle.fontFamily.

  • The maxCacheObjects property defines how large the cache is allowed to be. If there are more files the files that haven't been used for the longest time will be removed.

    It is used to specify the cache configuration, Config, for CacheManager.

  • cacheStalePeriod is the time duration in which a cache object is considered 'stale'. When a file is cached but not being used for a certain time the file will be deleted

    Defaults to 365 days.

    It is used to specify the cache configuration, Config, for CacheManager.

Implementation

DynamicCachedFonts.fromFirebase({
  required String bucketUrl,
  required this.fontFamily,
  this.maxCacheObjects = kDefaultMaxCacheObjects,
  this.cacheStalePeriod = kDefaultCacheStalePeriod,
})  : assert(
        fontFamily != '',
        'fontFamily cannot be empty',
      ),
      assert(
        bucketUrl != '',
        'bucketUrl cannot be empty',
      ),
      urls = <String>[bucketUrl],
      _isFirebaseURL = true,
      _loaded = false;