cacheBase64 method

  1. @override
Future<File> cacheBase64(
  1. String key,
  2. String base64, {
  3. Duration maxAge = const Duration(days: 30),
  4. String fileExtension = 'jpg',
})
override

Implementation

@override
Future<File> cacheBase64(
  String key,
  String base64, {
  Duration maxAge = const Duration(days: 30),
  String fileExtension = 'jpg',
}) async {
  // Check if the image file is not in the cache
  final fileInfo = await _cacheManager.getFileFromCache(key);
  final file = fileInfo?.file;
  if (file == null) {
    // Convert Base64 to Bytes of array
    final imageBytes = await compute(_convertBase64ToBytes, base64);

    // Put the image file in the cache
    final files = await _cacheManager.putFile(
      key,
      imageBytes,
      maxAge: maxAge,
      fileExtension: fileExtension,
    );
    return files;
  }
  return file;
}