Finished drawer and also now showing expenses as they are added!

This commit is contained in:
Hyperling 2025-02-05 14:04:35 -07:00
parent 87392cc73c
commit ecbac615e9
2 changed files with 159 additions and 190 deletions

View File

@ -41,6 +41,10 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
var pageSelected = 0;
refresh() {
setState(() {});
}
@override
Widget build(BuildContext context) {
Widget page;
@ -48,7 +52,9 @@ class _HomePageState extends State<HomePage> {
switch (pageSelected) {
case 0:
page = ExpensePage();
dialog = ExpenseInputDialog();
dialog = ExpenseInputDialog(
notifyParent: refresh,
);
case 1:
page = IncomePage();
case 2:
@ -79,11 +85,8 @@ class _HomePageState extends State<HomePage> {
return LayoutBuilder(builder: (context, constraints) {
return Scaffold(
// TODO: Add a drawer instead of nav rail.
body: Row(
children: [
SafeArea(
child: NavigationRail(
appBar: AppBar(title: Text("Expense Tracker")),
drawer: NavigationRail(
extended: constraints.maxWidth >= 800,
destinations: [
NavigationRailDestination(
@ -100,7 +103,7 @@ class _HomePageState extends State<HomePage> {
),
NavigationRailDestination(
icon: Icon(Icons.bar_chart),
label: Text('Projections'),
label: Text('Reports'),
),
NavigationRailDestination(
icon: Icon(Icons.settings),
@ -111,18 +114,16 @@ class _HomePageState extends State<HomePage> {
onDestinationSelected: (value) {
setState(() {
pageSelected = value;
Navigator.pop(context);
});
},
),
),
Expanded(
body: Center(
child: Container(
color: Theme.of(context).colorScheme.primaryContainer,
child: page,
),
),
],
),
floatingActionButton: floatingButton,
);
});

View File

@ -33,27 +33,16 @@ class ExpensePage extends StatelessWidget {
),
),
);
});
/*
return ListView(
children: [
ListTile(
title: Text("Fake Item 1"),
subtitle: Text("30.00 / month"),
),
ListTile(
title: Text("Fake Item 2"),
subtitle: Text("180.00 / year"),
),
],
},
);
*/
}
}
class ExpenseInputDialog extends StatefulWidget {
final Function() notifyParent;
const ExpenseInputDialog({
super.key,
required this.notifyParent,
});
@override
@ -70,9 +59,6 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
@override
Widget build(BuildContext context) {
const inputWidth = 300.0;
const inputHeight = 50.0;
List<DropdownMenuItem> freqValues = [];
for (var freq in Frequency.values) {
freqValues.add(DropdownMenuItem(value: freq, child: Text(freq.title)));
@ -83,12 +69,9 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
title: Center(child: Text("Add New Expense")),
content: Form(
key: _expenseFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
//autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextFormField(
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name",
@ -104,14 +87,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_name = newValue!;
},
),
),
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextFormField(
TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: "Cost", hintText: "Example: 10.00"),
decoration:
InputDecoration(labelText: "Cost", hintText: "Example: 10.00"),
validator: (value) {
if (value!.isEmpty) {
return "Cost must be provided.";
@ -125,11 +104,7 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_cost = double.parse(newValue!);
},
),
),
SizedBox(
width: inputWidth,
height: inputHeight,
child: DropdownButtonFormField(
DropdownButtonFormField(
items: freqValues,
decoration: InputDecoration(
labelText: "Recurrence", hintText: "Example: Monthly"),
@ -146,11 +121,7 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_freq = newValue;
},
),
),
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextFormField(
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Description",
@ -162,14 +133,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_desc = newValue!;
},
),
),
]),
),
actions: [
SizedBox(
width: inputWidth,
height: inputHeight,
child: Row(
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
@ -195,6 +162,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
description: _desc),
);
});
widget.notifyParent();
print(expenses.toString());
for (var expense in expenses) {
print(expense.toString());
@ -206,7 +175,6 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
label: Text('Submit'),
),
],
),
)
],
);