Refactor to add header to the Tracked Item pages.
This commit is contained in:
parent
2d9c93fec4
commit
e896611bd1
@ -2,21 +2,26 @@ enum ItemType {
|
||||
expense(
|
||||
title: "Expense",
|
||||
plural: "Expenses",
|
||||
description: "Items which cost revenue, or decrease asset value.",
|
||||
),
|
||||
income(
|
||||
title: "Income",
|
||||
plural: "Incomes",
|
||||
plural: "Income",
|
||||
description: "Items which bring in revenue, or increase asset value.",
|
||||
),
|
||||
asset(
|
||||
title: "Asset",
|
||||
plural: "Assets",
|
||||
description: "Value which has been earned and can be spent.",
|
||||
);
|
||||
|
||||
const ItemType({
|
||||
required this.title,
|
||||
required this.plural,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String plural;
|
||||
final String description;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class _HomePageState extends State<HomePage> {
|
||||
switch (pageSelected) {
|
||||
case 0:
|
||||
page = TrackedItemPage(
|
||||
assetsToLoad: DatabaseHelper.instance.getExpenses(),
|
||||
assetType: ItemType.expense,
|
||||
notifyParent: refresh,
|
||||
);
|
||||
dialog = TrackedItemInputDialog(
|
||||
@ -66,7 +66,7 @@ class _HomePageState extends State<HomePage> {
|
||||
break;
|
||||
case 1:
|
||||
page = TrackedItemPage(
|
||||
assetsToLoad: DatabaseHelper.instance.getIncomes(),
|
||||
assetType: ItemType.income,
|
||||
notifyParent: refresh,
|
||||
);
|
||||
dialog = TrackedItemInputDialog(
|
||||
@ -76,7 +76,7 @@ class _HomePageState extends State<HomePage> {
|
||||
break;
|
||||
case 2:
|
||||
page = TrackedItemPage(
|
||||
assetsToLoad: DatabaseHelper.instance.getAssets(),
|
||||
assetType: ItemType.asset,
|
||||
notifyParent: refresh,
|
||||
);
|
||||
dialog = TrackedItemInputDialog(
|
||||
@ -120,15 +120,15 @@ class _HomePageState extends State<HomePage> {
|
||||
destinations: [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.payment),
|
||||
label: Text('Expenses'),
|
||||
label: Text(ItemType.expense.plural),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.account_balance),
|
||||
label: Text('Income'),
|
||||
label: Text(ItemType.income.plural),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.attach_money),
|
||||
label: Text('Liquid Assets'),
|
||||
label: Text(ItemType.asset.plural),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.bar_chart),
|
||||
|
@ -11,12 +11,12 @@ import '/models/frequency.dart';
|
||||
import '/db.dart';
|
||||
|
||||
class TrackedItemPage extends StatefulWidget {
|
||||
final Future<List<TrackedItem>> assetsToLoad;
|
||||
final ItemType assetType;
|
||||
final Function() notifyParent;
|
||||
|
||||
const TrackedItemPage({
|
||||
super.key,
|
||||
required this.assetsToLoad,
|
||||
required this.assetType,
|
||||
required this.notifyParent,
|
||||
});
|
||||
|
||||
@ -25,12 +25,28 @@ class TrackedItemPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
late Future<List<TrackedItem>> _assetsToLoad;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
switch (widget.assetType) {
|
||||
case ItemType.expense:
|
||||
_assetsToLoad = DatabaseHelper.instance.getExpenses();
|
||||
break;
|
||||
case ItemType.income:
|
||||
_assetsToLoad = DatabaseHelper.instance.getIncomes();
|
||||
break;
|
||||
case ItemType.asset:
|
||||
_assetsToLoad = DatabaseHelper.instance.getAssets();
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unsure whch asset group to load.");
|
||||
}
|
||||
|
||||
return FutureBuilder<List<TrackedItem>>(
|
||||
future: widget.assetsToLoad,
|
||||
future: _assetsToLoad,
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<List<TrackedItem>> snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
@ -46,7 +62,26 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
"Add items to get started.",
|
||||
softWrap: true,
|
||||
)
|
||||
: ListView.builder(
|
||||
: Column(
|
||||
children: [
|
||||
Text(
|
||||
"${widget.assetType.plural}",
|
||||
style: TextStyle(
|
||||
fontSize: 24.0,
|
||||
decoration: TextDecoration.underline,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
/*Text(
|
||||
"${widget.assetType.description}",
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
decoration: TextDecoration.none,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),*/
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (_, index) {
|
||||
final TrackedItem curr = snapshot.data![index];
|
||||
@ -63,7 +98,9 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
}
|
||||
final String itemDescription = curr.description;
|
||||
|
||||
final double itemDayAmount, itemMonthAmount, itemYearAmount;
|
||||
final double itemDayAmount,
|
||||
itemMonthAmount,
|
||||
itemYearAmount;
|
||||
final String estimateSymbolDaily,
|
||||
estimateSymbolMonthly,
|
||||
estimateSymbolYearly;
|
||||
@ -73,7 +110,9 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
estimateSymbolDaily = curr.frequency!.numDays
|
||||
.toStringAsFixed(2)
|
||||
.endsWith(".00") &&
|
||||
itemDayAmount.toStringAsFixed(3).endsWith("0")
|
||||
itemDayAmount
|
||||
.toStringAsFixed(3)
|
||||
.endsWith("0")
|
||||
? ""
|
||||
: "~";
|
||||
|
||||
@ -82,7 +121,9 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
estimateSymbolMonthly = curr.frequency!.timesPerYear
|
||||
.toStringAsFixed(2)
|
||||
.endsWith(".00") &&
|
||||
itemMonthAmount.toStringAsFixed(3).endsWith("0")
|
||||
itemMonthAmount
|
||||
.toStringAsFixed(3)
|
||||
.endsWith("0")
|
||||
? ""
|
||||
: "~";
|
||||
|
||||
@ -90,7 +131,9 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
estimateSymbolYearly = curr.frequency!.timesPerYear
|
||||
.toStringAsFixed(2)
|
||||
.endsWith(".00") &&
|
||||
itemYearAmount.toStringAsFixed(3).endsWith("0")
|
||||
itemYearAmount
|
||||
.toStringAsFixed(3)
|
||||
.endsWith("0")
|
||||
? ""
|
||||
: "~";
|
||||
} else {
|
||||
@ -102,7 +145,8 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
estimateSymbolYearly = "";
|
||||
}
|
||||
|
||||
final String monthlyTitle = curr.type == ItemType.asset
|
||||
final String monthlyTitle =
|
||||
curr.type == ItemType.asset
|
||||
? ""
|
||||
: " ${Frequency.monthly.title}";
|
||||
|
||||
@ -196,7 +240,8 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
itemTitle,
|
||||
@ -221,7 +266,8 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
itemTopText,
|
||||
@ -244,6 +290,9 @@ class _TrackedItemPageState extends State<TrackedItemPage> {
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user