Assets are now being displayed properly.

This commit is contained in:
Hyperling 2025-03-08 07:40:03 -07:00
parent a92cc00291
commit 8b9e0bfe54

View File

@ -70,26 +70,45 @@ class SummaryCardForTotals extends StatelessWidget {
if (!snapshot.hasData) { if (!snapshot.hasData) {
return Text('Loading $summaryTypeLabel Section...'); return Text('Loading $summaryTypeLabel Section...');
} }
// TODO: Do not show all 3 sections or any text for Assets.
// Calculate the total fields based on item type.
double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0; double dailyTotal = 0, monthlyTotal = 0, yearlyTotal = 0;
bool isAsset = false;
for (TrackedItem e in snapshot.data!) { for (TrackedItem e in snapshot.data!) {
dailyTotal += e.calcComparableAmountDaily(); if (e.type == ItemType.asset) {
monthlyTotal += e.calcComparableAmountYearly() / 12; monthlyTotal += e.amount;
yearlyTotal += e.calcComparableAmountYearly(); isAsset = true;
} else {
dailyTotal += e.calcComparableAmountDaily();
monthlyTotal += e.calcComparableAmountYearly() / 12;
yearlyTotal += e.calcComparableAmountYearly();
}
} }
// Determine what needs displayed for the item type.
String dailyEstimate = String dailyEstimate =
dailyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~", dailyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~",
monthlyEstimate = monthlyEstimate =
monthlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~", monthlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~",
yearlyEstimate = yearlyEstimate =
yearlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~"; yearlyTotal.toStringAsFixed(3).endsWith("0") ? "" : "~";
String leftText = "", middleText = "", rightText = "";
if (isAsset) {
middleText = "$monthlyEstimate${monthlyTotal.toStringAsFixed(2)}";
} else {
leftText = "$dailyEstimate${dailyTotal.toStringAsFixed(2)} Daily";
middleText =
"$monthlyEstimate${monthlyTotal.toStringAsFixed(2)} Monthly";
rightText =
"$yearlyEstimate${yearlyTotal.toStringAsFixed(2)} Yearly";
}
// Return the UI element.
return SummaryCard( return SummaryCard(
name: "$summaryTypeLabel Totals", name: "$summaryTypeLabel Totals",
leftText: "$dailyEstimate${dailyTotal.toStringAsFixed(2)} Daily", leftText: leftText,
middleText: middleText: middleText,
"$monthlyEstimate${monthlyTotal.toStringAsFixed(2)} Monthly", rightText: rightText,
rightText:
"$yearlyEstimate${yearlyTotal.toStringAsFixed(2)} Yearly",
); );
}); });
} }