From 8c31d868b9fbe7609eb1c53836f261a5f912ee75 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Fri, 7 Feb 2025 10:24:20 -0700 Subject: [PATCH] Add a daily estimate. Move estimates to the right of the list item. --- lib/models/expense.dart | 5 +++++ lib/models/frequency.dart | 14 ++++++++++-- lib/pages/expense.dart | 46 ++++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/models/expense.dart b/lib/models/expense.dart index f983812..0cc39d2 100644 --- a/lib/models/expense.dart +++ b/lib/models/expense.dart @@ -12,6 +12,7 @@ class Expense { required this.frequency, required this.description}); + @override String toString() { return "$name, $cost, ${frequency.title}, $description"; } @@ -19,4 +20,8 @@ class Expense { double calcComparableCost() { return cost * frequency.timesPerYear; } + + double calcComparableCostDaily() { + return cost / frequency.numDays; + } } diff --git a/lib/models/frequency.dart b/lib/models/frequency.dart index 8895ea6..d74fe16 100644 --- a/lib/models/frequency.dart +++ b/lib/models/frequency.dart @@ -4,50 +4,60 @@ enum Frequency { title: "Daily", hint: "Once Per Day", timesPerYear: 364.25, + numDays: 1, ), weekly( title: "Weekly", hint: "Once Per Week", - timesPerYear: (364.25/7), + timesPerYear: (364.25 / 7), + numDays: 7, ), biweekly( title: "Biweekly", hint: "Every Other Week", - timesPerYear: (364.25/7/2), + timesPerYear: (364.25 / 14), + numDays: 14, ), bimonthly( title: "Bimonthly", hint: "Twice Per Month", timesPerYear: 24, + numDays: (364.25 / 24), ), monthly( title: "Monthly", hint: "Once Per Month", timesPerYear: 12, + numDays: (364.25 / 12), ), quarterly( title: "Quarterly", hint: "Every Three Months", timesPerYear: 4, + numDays: (364.25 / 4), ), biannual( title: "Biannual", hint: "Twice Per Year", timesPerYear: 2, + numDays: (364.25 / 2), ), yearly( title: "Yearly", hint: "Once Per Year", timesPerYear: 1, + numDays: 364.25, ); const Frequency({ required this.title, required this.hint, required this.timesPerYear, + required this.numDays, }); final String title; final String hint; final double timesPerYear; + final double numDays; } diff --git a/lib/pages/expense.dart b/lib/pages/expense.dart index debe190..e78f0b0 100644 --- a/lib/pages/expense.dart +++ b/lib/pages/expense.dart @@ -35,12 +35,20 @@ class _ExpensePageState extends State { itemCount: expenses.length, itemBuilder: (_, index) { final Expense curr = expenses[index]; - final String estimateSymbol = switch (curr.frequency.timesPerYear - .toStringAsFixed(2) - .endsWith(".00")) { - true => "", - false => "~", - }; + final String estimateSymbolYearly = curr.frequency.timesPerYear + .toStringAsFixed(2) + .endsWith(".00") && + curr.calcComparableCost().toStringAsFixed(3).endsWith("0") + ? "" + : "~"; + final String estimateSymbolDaily = + curr.frequency.numDays.toStringAsFixed(2).endsWith(".00") && + curr + .calcComparableCostDaily() + .toStringAsFixed(3) + .endsWith("0") + ? "" + : "~"; return Padding( padding: const EdgeInsets.all(4.0), child: Dismissible( @@ -113,11 +121,6 @@ class _ExpensePageState extends State { "${curr.cost.toStringAsFixed(2)} ${curr.frequency.title}", style: TextStyle(fontSize: 12.0), ), - if (curr.frequency != Frequency.yearly) - Text( - "$estimateSymbol${curr.calcComparableCost().toStringAsFixed(2)} Yearly", - style: TextStyle(fontSize: 12.0), - ), ], ), Expanded( @@ -132,6 +135,21 @@ class _ExpensePageState extends State { ), ), ), + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + //if (curr.frequency != Frequency.daily) + Text( + "$estimateSymbolDaily${curr.calcComparableCostDaily().toStringAsFixed(2)} ${Frequency.daily.title}", + style: TextStyle(fontSize: 12.0), + ), + //if (curr.frequency != Frequency.yearly) + Text( + "$estimateSymbolYearly${curr.calcComparableCost().toStringAsFixed(2)} ${Frequency.yearly.title}", + style: TextStyle(fontSize: 12.0), + ), + ], + ), ], ), ), @@ -207,6 +225,7 @@ class _ExpenseInputDialogState extends State { children: [ TextFormField( keyboardType: TextInputType.text, + textCapitalization: TextCapitalization.words, decoration: InputDecoration( labelText: "Name", hintText: "Example: Red Pocket", @@ -297,10 +316,11 @@ class _ExpenseInputDialogState extends State { ), TextFormField( keyboardType: TextInputType.text, + textCapitalization: TextCapitalization.sentences, decoration: InputDecoration( labelText: "Description", - hintText: "Example: 1GB data, unlimited talk & text.", - hintStyle: TextStyle(fontSize: 10.0), + hintText: "Example: 1GB data with unlimited talk & text.", + hintStyle: TextStyle(fontSize: 8.0), errorStyle: TextStyle(fontSize: 10.0), ), initialValue: _desc,