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

View File

@ -17,13 +17,14 @@ class CacheView extends StatefulWidget {
@override @override
State<CacheView> createState() => _CacheViewState(); State<CacheView> createState() => _CacheViewState();
void clear() { Future<void> clear() async {
Localstore.instance.collection(collection).delete(); await Localstore.instance.collection(collection).delete();
} }
Future<int> totalSize() async { Future<int> totalSize() async {
var data = await Localstore.instance.collection(collection).get(); 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;
} }
} }

View File

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