Skip to content

Instantly share code, notes, and snippets.

@VB10
Last active June 6, 2021 02:10
Show Gist options
  • Save VB10/2ed6658eecf5df32aeba66cd896bc088 to your computer and use it in GitHub Desktop.
Save VB10/2ed6658eecf5df32aeba66cd896bc088 to your computer and use it in GitHub Desktop.
@override
Future<ItemModel?> takeItemWithCache(int? id) async {
if (_directory == null) {
final appDirectory = await createDirectory();
_directory ??= await Directory('${appDirectory.path}/$_localPath').create();
}
final items = await _directory!.list().toSet();
final _item = items.firstWhereOrNull((element) => element.path.contains('$id'));
if (_item != null) {
if (await _item.exists()) {
final file = File(_item.path);
final jsonBody = json.decode(await file.readAsString());
final feedItem = ItemModel.fromJson(jsonBody);
feedItem.itemValues = encrypData.decryptFile(feedItem.itemValues ?? '');
return feedItem;
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment