DynamicCachedFonts.family constructor

DynamicCachedFonts.family({
  1. required List<String> urls,
  2. required String fontFamily,
  3. int maxCacheObjects = kDefaultMaxCacheObjects,
  4. Duration cacheStalePeriod = kDefaultCacheStalePeriod,
})

Allows dynamically loading fonts from the given list of url and caching them. The fontFamily groups a series of related font assets, each of which defines how to render a specific FontWeight and FontStyle within the family.

  • REQUIRED The urls property is used to specify the download urls for the required fonts. It should be a list of valid http/https urls which point to font files.

    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.family({
  required this.urls,
  required this.fontFamily,
  this.maxCacheObjects = kDefaultMaxCacheObjects,
  this.cacheStalePeriod = kDefaultCacheStalePeriod,
})  : assert(
        fontFamily != '',
        'fontFamily cannot be empty',
      ),
      assert(
        urls.length > 1,
        'At least 2 urls have to be provided. To load a single font url, use the default constructor',
      ),
      assert(
        urls.every(
          (String url) => url != '',
        ),
        'url cannot be empty',
      ),
      _isFirebaseURL = false,
      _loaded = false;