From 147178e4ddefdbcbe3c1131db70a65ce1f12168c Mon Sep 17 00:00:00 2001 From: Hyperling Date: Thu, 27 Mar 2025 11:58:26 -0700 Subject: [PATCH] Fix the projections not loading if any item type was left unused. --- lib/pages/report.dart | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/pages/report.dart b/lib/pages/report.dart index e30bbeb..6210dfa 100644 --- a/lib/pages/report.dart +++ b/lib/pages/report.dart @@ -48,15 +48,15 @@ class _ProjectionPageState extends State { // Summaries for display as well as calculation of totals for projections. Widget expenseSummary = SummaryCardForTotals( list: DatabaseHelper.instance.getExpenses(), - summaryTypeLabel: ItemType.expense.title, + itemType: ItemType.expense, ); Widget incomeSummary = SummaryCardForTotals( list: DatabaseHelper.instance.getIncomes(), - summaryTypeLabel: ItemType.income.title, + itemType: ItemType.income, ); Widget assetSummary = SummaryCardForTotals( list: DatabaseHelper.instance.getAssets(), - summaryTypeLabel: ItemType.asset.title, + itemType: ItemType.asset, ); // Calculations for the projections. @@ -155,14 +155,16 @@ class SummaryCardForTotals extends StatelessWidget { const SummaryCardForTotals({ super.key, required this.list, - required this.summaryTypeLabel, + required this.itemType, }); final Future> list; - final String summaryTypeLabel; + final ItemType itemType; @override Widget build(BuildContext context) { + String summaryTypeLabel = itemType.title.toString(); + return FutureBuilder>( future: list, builder: ( @@ -175,12 +177,9 @@ class SummaryCardForTotals extends StatelessWidget { // Calculate the total fields based on item type. double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0; - ItemType? itemType; for (TrackedItem e in snapshot.data!) { - if (itemType == null) { - itemType = e.type!; - } else if (itemType != e.type) { - throw "List in SummaryCardForTotals has multiple item types, abort!"; + if (e.type != itemType) { + throw "List in SummaryCardForTotals has incorrect item types, abort!"; } if (e.type == ItemType.asset) { @@ -194,9 +193,6 @@ class SummaryCardForTotals extends StatelessWidget { /* Load page variables based on calculated totals. */ switch (itemType) { - case null: - break; - case ItemType.asset: _assetTotal = monthlyTotal; break;