getBytes method
get bytes(List
if cache entry is expired or not found, returns null.
Implementation
Future<List<int>?> getBytes(String key) async {
if (!_initialized) {
await init();
}
final timeout = remainingDurationForKey(key);
if (timeout.isNegative) {
return null;
}
if (kIsWeb) {
if (_db == null) return null;
var txn = _db!.transaction(_basePath, idbModeReadOnly);
var store = txn.objectStore(_basePath);
var value = await store.getObject(key) as List;
await txn.completed;
List<dynamic> dynList = value[0];
return dynList.cast<int>();
} else {
final filePath = await _pathForKey(key);
if (await FileSystemEntity.type(filePath) !=
FileSystemEntityType.notFound) {
return File(filePath).readAsBytes();
} else {
return null;
}
}
}