Add a daily estimate. Move estimates to the right of the list item.
This commit is contained in:
parent
9d478b9cbf
commit
8c31d868b9
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -35,12 +35,20 @@ class _ExpensePageState extends State<ExpensePage> {
|
||||
itemCount: expenses.length,
|
||||
itemBuilder: (_, index) {
|
||||
final Expense curr = expenses[index];
|
||||
final String estimateSymbol = switch (curr.frequency.timesPerYear
|
||||
final String estimateSymbolYearly = curr.frequency.timesPerYear
|
||||
.toStringAsFixed(2)
|
||||
.endsWith(".00")) {
|
||||
true => "",
|
||||
false => "~",
|
||||
};
|
||||
.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<ExpensePage> {
|
||||
"${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<ExpensePage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
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<ExpenseInputDialog> {
|
||||
children: [
|
||||
TextFormField(
|
||||
keyboardType: TextInputType.text,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Name",
|
||||
hintText: "Example: Red Pocket",
|
||||
@ -297,10 +316,11 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
),
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user