Fix estimated filesize not displaying correctly when only one cache exists

This commit is contained in:
Elias Müller 2023-06-04 02:33:59 +02:00
parent 95f14da13f
commit 41d4d3dd3f
2 changed files with 5 additions and 4 deletions
lib/view/settings

@ -17,13 +17,14 @@ class CacheView extends StatefulWidget {
@override
State<CacheView> createState() => _CacheViewState();
void clear() {
Localstore.instance.collection(collection).delete();
Future<void> clear() async {
await Localstore.instance.collection(collection).delete();
}
Future<int> totalSize() async {
var data = await Localstore.instance.collection(collection).get();
return data!.values.reduce((a, b) => jsonEncode(a).length + jsonEncode(b).length) * 8;
if(data!.length <= 1) return jsonEncode(data.values.first).length * 8;
return data.values.reduce((a, b) => jsonEncode(a).length + jsonEncode(b).length) * 8;
}
}

@ -196,7 +196,7 @@ class _SettingsState extends State<Settings> {
title: "Cache löschen",
content: "Alle cache Einträge werden gelöscht. Der cache wird bei benutzung der App erneut aufgebaut",
confirmButton: "Unwiederruflich löschen",
onConfirm: () => const CacheView().clear(),
onConfirm: () => const CacheView().clear().then((value) => setState((){})),
).asDialog(context);
},
trailing: const Icon(Icons.arrow_right),