cacheFile static method

Future<String> cacheFile(
  1. String key,
  2. File file
)

Cache a file to temporary storage

Implementation

static Future<String> cacheFile(String key, File file) async {
  _ensureInitialized();

  final cacheDir = _cacheDir!;
  final cachedFile = File('${cacheDir.path}/$key');

  if (await file.exists()) {
    await file.copy(cachedFile.path);
    return cachedFile.path;
  }

  throw Exception('Source file does not exist');
}