Skip to content

Instantly share code, notes, and snippets.

@VB10
Created June 6, 2021 02:04
Show Gist options
  • Save VB10/f4932d7100b47d49bc4134184a830bc7 to your computer and use it in GitHub Desktop.
Save VB10/f4932d7100b47d49bc4134184a830bc7 to your computer and use it in GitHub Desktop.
@override
Future<void> clearAllDatasWithExpiry() async {
final directory = await createDirectory();
final itemDirectory = await Directory('${directory.path}/$_localPath').create();
final items = await itemDirectory.list().toSet();
await Future.forEach<FileSystemEntity>(items, (element) async {
final file = File(element.path);
final jsonBody = json.decode(await file.readAsString());
final feedItem = ItemModel.fromJson(jsonBody);
final _itemDate = feedItem.date ?? DateTime.now().add(Duration(days: _expiryValue + 1));
if (_itemDate.difference(DateTime.now()).inDays.abs() > _expiryValue) {
Logger().i('${feedItem.id} has removed');
await file.delete();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment