Fix estimated filesize not displaying correctly when only one cache exists

This commit is contained in:
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
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;
}
}