From 821952ea29bb02a7a01383ec77b2b117200b463a Mon Sep 17 00:00:00 2001 From: { Aman } Date: Wed, 3 Dec 2025 22:08:12 +0530 Subject: [PATCH] Fixed a sevre bug --- lib/Components/quick_send.dart | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Components/quick_send.dart b/lib/Components/quick_send.dart index 4119571..7b3d1c2 100755 --- a/lib/Components/quick_send.dart +++ b/lib/Components/quick_send.dart @@ -31,21 +31,25 @@ class _QuickSendRowState extends State { Future> fetchCategoriesSortedByUsage() async { final user = FirebaseAuth.instance.currentUser; - if (user == null) { - return []; - } + if (user == null) return []; final txRef = FirebaseFirestore.instance .collection('users') - .doc(user.email) // or user.uid + .doc(user.email) .collection('transactions'); try { final snapshot = await txRef.get(); - Map categoryCounts = {}; + for (var doc in snapshot.docs) { - final category = doc['category'] as String?; + final data = doc.data(); + + // Safe category reading + final category = data.containsKey('category') + ? data['category'] as String? + : null; + if (category != null && category.isNotEmpty) { categoryCounts[category] = (categoryCounts[category] ?? 0) + 1; } @@ -53,6 +57,7 @@ class _QuickSendRowState extends State { final sortedCategories = categoryCounts.entries.toList() ..sort((a, b) => b.value.compareTo(a.value)); + return sortedCategories.map((e) => e.key).toList(); } catch (e) { debugPrint('Error fetching categories sorted by usage: $e'); @@ -60,6 +65,7 @@ class _QuickSendRowState extends State { } } + Future _loadCategoriesSortedByUsage() async { setState(() { loading = true;