Fix the projections not loading if any item type was left unused.

This commit is contained in:
Hyperling 2025-03-27 11:58:26 -07:00
parent c39e09b2b6
commit 147178e4dd

View File

@ -48,15 +48,15 @@ class _ProjectionPageState extends State<ProjectionPage> {
// Summaries for display as well as calculation of totals for projections. // Summaries for display as well as calculation of totals for projections.
Widget expenseSummary = SummaryCardForTotals( Widget expenseSummary = SummaryCardForTotals(
list: DatabaseHelper.instance.getExpenses(), list: DatabaseHelper.instance.getExpenses(),
summaryTypeLabel: ItemType.expense.title, itemType: ItemType.expense,
); );
Widget incomeSummary = SummaryCardForTotals( Widget incomeSummary = SummaryCardForTotals(
list: DatabaseHelper.instance.getIncomes(), list: DatabaseHelper.instance.getIncomes(),
summaryTypeLabel: ItemType.income.title, itemType: ItemType.income,
); );
Widget assetSummary = SummaryCardForTotals( Widget assetSummary = SummaryCardForTotals(
list: DatabaseHelper.instance.getAssets(), list: DatabaseHelper.instance.getAssets(),
summaryTypeLabel: ItemType.asset.title, itemType: ItemType.asset,
); );
// Calculations for the projections. // Calculations for the projections.
@ -155,14 +155,16 @@ class SummaryCardForTotals extends StatelessWidget {
const SummaryCardForTotals({ const SummaryCardForTotals({
super.key, super.key,
required this.list, required this.list,
required this.summaryTypeLabel, required this.itemType,
}); });
final Future<List<TrackedItem>> list; final Future<List<TrackedItem>> list;
final String summaryTypeLabel; final ItemType itemType;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String summaryTypeLabel = itemType.title.toString();
return FutureBuilder<List<TrackedItem>>( return FutureBuilder<List<TrackedItem>>(
future: list, future: list,
builder: ( builder: (
@ -175,12 +177,9 @@ class SummaryCardForTotals extends StatelessWidget {
// Calculate the total fields based on item type. // Calculate the total fields based on item type.
double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0; double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0;
ItemType? itemType;
for (TrackedItem e in snapshot.data!) { for (TrackedItem e in snapshot.data!) {
if (itemType == null) { if (e.type != itemType) {
itemType = e.type!; throw "List in SummaryCardForTotals has incorrect item types, abort!";
} else if (itemType != e.type) {
throw "List in SummaryCardForTotals has multiple item types, abort!";
} }
if (e.type == ItemType.asset) { if (e.type == ItemType.asset) {
@ -194,9 +193,6 @@ class SummaryCardForTotals extends StatelessWidget {
/* Load page variables based on calculated totals. */ /* Load page variables based on calculated totals. */
switch (itemType) { switch (itemType) {
case null:
break;
case ItemType.asset: case ItemType.asset:
_assetTotal = monthlyTotal; _assetTotal = monthlyTotal;
break; break;