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.frequency,
|
||||||
required this.description});
|
required this.description});
|
||||||
|
|
||||||
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return "$name, $cost, ${frequency.title}, $description";
|
return "$name, $cost, ${frequency.title}, $description";
|
||||||
}
|
}
|
||||||
@ -19,4 +20,8 @@ class Expense {
|
|||||||
double calcComparableCost() {
|
double calcComparableCost() {
|
||||||
return cost * frequency.timesPerYear;
|
return cost * frequency.timesPerYear;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double calcComparableCostDaily() {
|
||||||
|
return cost / frequency.numDays;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,50 +4,60 @@ enum Frequency {
|
|||||||
title: "Daily",
|
title: "Daily",
|
||||||
hint: "Once Per Day",
|
hint: "Once Per Day",
|
||||||
timesPerYear: 364.25,
|
timesPerYear: 364.25,
|
||||||
|
numDays: 1,
|
||||||
),
|
),
|
||||||
weekly(
|
weekly(
|
||||||
title: "Weekly",
|
title: "Weekly",
|
||||||
hint: "Once Per Week",
|
hint: "Once Per Week",
|
||||||
timesPerYear: (364.25/7),
|
timesPerYear: (364.25 / 7),
|
||||||
|
numDays: 7,
|
||||||
),
|
),
|
||||||
biweekly(
|
biweekly(
|
||||||
title: "Biweekly",
|
title: "Biweekly",
|
||||||
hint: "Every Other Week",
|
hint: "Every Other Week",
|
||||||
timesPerYear: (364.25/7/2),
|
timesPerYear: (364.25 / 14),
|
||||||
|
numDays: 14,
|
||||||
),
|
),
|
||||||
bimonthly(
|
bimonthly(
|
||||||
title: "Bimonthly",
|
title: "Bimonthly",
|
||||||
hint: "Twice Per Month",
|
hint: "Twice Per Month",
|
||||||
timesPerYear: 24,
|
timesPerYear: 24,
|
||||||
|
numDays: (364.25 / 24),
|
||||||
),
|
),
|
||||||
monthly(
|
monthly(
|
||||||
title: "Monthly",
|
title: "Monthly",
|
||||||
hint: "Once Per Month",
|
hint: "Once Per Month",
|
||||||
timesPerYear: 12,
|
timesPerYear: 12,
|
||||||
|
numDays: (364.25 / 12),
|
||||||
),
|
),
|
||||||
quarterly(
|
quarterly(
|
||||||
title: "Quarterly",
|
title: "Quarterly",
|
||||||
hint: "Every Three Months",
|
hint: "Every Three Months",
|
||||||
timesPerYear: 4,
|
timesPerYear: 4,
|
||||||
|
numDays: (364.25 / 4),
|
||||||
),
|
),
|
||||||
biannual(
|
biannual(
|
||||||
title: "Biannual",
|
title: "Biannual",
|
||||||
hint: "Twice Per Year",
|
hint: "Twice Per Year",
|
||||||
timesPerYear: 2,
|
timesPerYear: 2,
|
||||||
|
numDays: (364.25 / 2),
|
||||||
),
|
),
|
||||||
yearly(
|
yearly(
|
||||||
title: "Yearly",
|
title: "Yearly",
|
||||||
hint: "Once Per Year",
|
hint: "Once Per Year",
|
||||||
timesPerYear: 1,
|
timesPerYear: 1,
|
||||||
|
numDays: 364.25,
|
||||||
);
|
);
|
||||||
|
|
||||||
const Frequency({
|
const Frequency({
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.hint,
|
required this.hint,
|
||||||
required this.timesPerYear,
|
required this.timesPerYear,
|
||||||
|
required this.numDays,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
final String hint;
|
final String hint;
|
||||||
final double timesPerYear;
|
final double timesPerYear;
|
||||||
|
final double numDays;
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,20 @@ class _ExpensePageState extends State<ExpensePage> {
|
|||||||
itemCount: expenses.length,
|
itemCount: expenses.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final Expense curr = expenses[index];
|
final Expense curr = expenses[index];
|
||||||
final String estimateSymbol = switch (curr.frequency.timesPerYear
|
final String estimateSymbolYearly = curr.frequency.timesPerYear
|
||||||
.toStringAsFixed(2)
|
.toStringAsFixed(2)
|
||||||
.endsWith(".00")) {
|
.endsWith(".00") &&
|
||||||
true => "",
|
curr.calcComparableCost().toStringAsFixed(3).endsWith("0")
|
||||||
false => "~",
|
? ""
|
||||||
};
|
: "~";
|
||||||
|
final String estimateSymbolDaily =
|
||||||
|
curr.frequency.numDays.toStringAsFixed(2).endsWith(".00") &&
|
||||||
|
curr
|
||||||
|
.calcComparableCostDaily()
|
||||||
|
.toStringAsFixed(3)
|
||||||
|
.endsWith("0")
|
||||||
|
? ""
|
||||||
|
: "~";
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(4.0),
|
padding: const EdgeInsets.all(4.0),
|
||||||
child: Dismissible(
|
child: Dismissible(
|
||||||
@ -113,11 +121,6 @@ class _ExpensePageState extends State<ExpensePage> {
|
|||||||
"${curr.cost.toStringAsFixed(2)} ${curr.frequency.title}",
|
"${curr.cost.toStringAsFixed(2)} ${curr.frequency.title}",
|
||||||
style: TextStyle(fontSize: 12.0),
|
style: TextStyle(fontSize: 12.0),
|
||||||
),
|
),
|
||||||
if (curr.frequency != Frequency.yearly)
|
|
||||||
Text(
|
|
||||||
"$estimateSymbol${curr.calcComparableCost().toStringAsFixed(2)} Yearly",
|
|
||||||
style: TextStyle(fontSize: 12.0),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Expanded(
|
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: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
textCapitalization: TextCapitalization.words,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Name",
|
labelText: "Name",
|
||||||
hintText: "Example: Red Pocket",
|
hintText: "Example: Red Pocket",
|
||||||
@ -297,10 +316,11 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
|||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
|
textCapitalization: TextCapitalization.sentences,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "Description",
|
labelText: "Description",
|
||||||
hintText: "Example: 1GB data, unlimited talk & text.",
|
hintText: "Example: 1GB data with unlimited talk & text.",
|
||||||
hintStyle: TextStyle(fontSize: 10.0),
|
hintStyle: TextStyle(fontSize: 8.0),
|
||||||
errorStyle: TextStyle(fontSize: 10.0),
|
errorStyle: TextStyle(fontSize: 10.0),
|
||||||
),
|
),
|
||||||
initialValue: _desc,
|
initialValue: _desc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user