getFile method

Future<Map<String, dynamic>?> getFile(
  1. String name
)

Returns a previously saved file under name with the function DittoCacheManager.store

Implementation

Future<Map<String, dynamic>?> getFile(String name) async {
  /// Tries to fetch the file from memory
  final memoryFile = await _manager.getFileFromMemory(name);
  if (memoryFile != null) {
    return jsonDecode(memoryFile.file.readAsStringSync());
  }

  /// Fallbacks on the cache
  final cachedFile = await _manager.getFileFromCache(name);
  if (cachedFile != null) {
    return jsonDecode(cachedFile.file.readAsStringSync());
  }

  /// There is no file named [name]
  return null;
}