Created
June 6, 2021 02:04
-
-
Save VB10/f4932d7100b47d49bc4134184a830bc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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