getSingleFile method

  1. @override
Future<File> getSingleFile(
  1. String url, {
  2. String? key,
  3. Map<String, String>? headers,
})
override

Get the file from the cache and/or online, depending on availability and age. Downloaded form url, headers can be used for example for authentication. When a file is cached and up to date it is return directly, when the cached file is too old the file is downloaded and returned after download. When a cached file is not available the newly downloaded file is returned.

Implementation

@override
Future<File> getSingleFile(
  String url, {
  String? key,
  Map<String, String>? headers,
}) async {
  key ??= url;
  final cacheFile = await getFileFromCache(key);
  if (cacheFile != null && cacheFile.validTill.isAfter(DateTime.now())) {
    return cacheFile.file;
  }
  return (await downloadFile(url, key: key, authHeaders: headers)).file;
}