From 21f67b8a36f1f3d763bf7696c8f0f2f2f867310e Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 12 Feb 2025 12:53:34 -0700 Subject: [PATCH] Added a monthly runner. Moved field values to be in variables outside of the Widget being returned. --- lib/pages/expense.dart | 71 ++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/lib/pages/expense.dart b/lib/pages/expense.dart index 2dc15d9..cb58c29 100644 --- a/lib/pages/expense.dart +++ b/lib/pages/expense.dart @@ -50,29 +50,58 @@ class _ExpensePageState extends State { itemBuilder: (_, index) { //List expenses = snapshot.data!; final RecurringTrackedType curr = snapshot.data![index]; + + final itemKey = Key(curr.id!.toString()); + final String itemTitle = curr.name; + final String itemAmount; + if (curr is RecurringTrackedType) { + itemAmount = + "${curr.amount.toStringAsFixed(2)} ${curr.frequency.title}"; + } else { + itemAmount = curr.amount.toStringAsFixed(2); + } + final String itemDescription = curr.description; + + final double itemDayAmount = + curr.calcComparableAmountDaily(); + final String estimateSymbolDaily = curr.frequency.numDays + .toStringAsFixed(2) + .endsWith(".00") && + itemDayAmount.toStringAsFixed(3).endsWith("0") + ? "" + : "~"; + + final double itemMonthAmount = + (curr.calcComparableAmountYearly() / 12); + final String estimateSymbolMonthly = curr + .frequency.timesPerYear + .toStringAsFixed(2) + .endsWith(".00") && + itemMonthAmount.toStringAsFixed(3).endsWith("0") + ? "" + : "~"; + + final double itemYearAmount = + curr.calcComparableAmountYearly(); final String estimateSymbolYearly = curr .frequency.timesPerYear .toStringAsFixed(2) .endsWith(".00") && - curr - .calcComparableAmountYearly() - .toStringAsFixed(3) - .endsWith("0") - ? "" - : "~"; - final String estimateSymbolDaily = curr.frequency.numDays - .toStringAsFixed(2) - .endsWith(".00") && - curr - .calcComparableAmountDaily() - .toStringAsFixed(3) - .endsWith("0") + itemYearAmount.toStringAsFixed(3).endsWith("0") ? "" : "~"; + + final String itemTopText = + "$estimateSymbolDaily${itemDayAmount.toStringAsFixed(2)} ${Frequency.daily.title}"; + final String itemMiddleText = + "$estimateSymbolMonthly${itemMonthAmount.toStringAsFixed(2)} ${Frequency.monthly.title}"; + final String itemBottomText = + "$estimateSymbolYearly${itemYearAmount.toStringAsFixed(2)} ${Frequency.yearly.title}"; + return Padding( padding: const EdgeInsets.all(4.0), child: Dismissible( - key: Key(curr.id!.toString()), + key: itemKey, background: Container( color: Colors.red, child: Row( @@ -135,11 +164,11 @@ class _ExpensePageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - curr.name, + itemTitle, style: TextStyle(fontSize: 20.0), ), Text( - "${curr.amount.toStringAsFixed(2)} ${curr.frequency.title}", + itemAmount, style: TextStyle(fontSize: 12.0), ), ], @@ -159,14 +188,16 @@ class _ExpensePageState extends State { Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ - //if (curr.frequency != Frequency.daily) Text( - "$estimateSymbolDaily${curr.calcComparableAmountDaily().toStringAsFixed(2)} ${Frequency.daily.title}", + itemTopText, style: TextStyle(fontSize: 12.0), ), - //if (curr.frequency != Frequency.yearly) Text( - "$estimateSymbolYearly${curr.calcComparableAmountYearly().toStringAsFixed(2)} ${Frequency.yearly.title}", + itemMiddleText, + style: TextStyle(fontSize: 12.0), + ), + Text( + itemBottomText, style: TextStyle(fontSize: 12.0), ), ],