cacheFont static method
Downloads and caches font from the url
with the given configuration.
-
REQUIRED The
url
property is used to specify the download url for the required font. It should be a valid http/https url which points to a font file. Currently, only OpenType (OTF) and TrueType (TTF) fonts are supported. -
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 deletedIt is used to specify the cache configuration, Config, for CacheManager.
Implementation
static Future<FileInfo> cacheFont(
String url, {
required int maxCacheObjects,
required Duration cacheStalePeriod,
}) async {
WidgetsFlutterBinding.ensureInitialized();
final String cacheKey = Utils.sanitizeUrl(url);
DynamicCachedFontsCacheManager.handleCacheManager(
cacheKey, cacheStalePeriod, maxCacheObjects);
final FileInfo font =
await DynamicCachedFontsCacheManager.getCacheManager(cacheKey)
.downloadFile(
url,
key: cacheKey,
);
Utils.verifyFileExtension(font.file);
devLog(<String>[
'Font file downloaded\n',
'Validity: ${font.validTill}',
'Download URL: ${font.originalUrl}',
]);
return font;
}