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> { class _HomePageState extends State<HomePage> {
var pageSelected = 0; var pageSelected = 0;
refresh() {
setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget page; Widget page;
@ -48,7 +52,9 @@ class _HomePageState extends State<HomePage> {
switch (pageSelected) { switch (pageSelected) {
case 0: case 0:
page = ExpensePage(); page = ExpensePage();
dialog = ExpenseInputDialog(); dialog = ExpenseInputDialog(
notifyParent: refresh,
);
case 1: case 1:
page = IncomePage(); page = IncomePage();
case 2: case 2:
@ -79,11 +85,8 @@ class _HomePageState extends State<HomePage> {
return LayoutBuilder(builder: (context, constraints) { return LayoutBuilder(builder: (context, constraints) {
return Scaffold( return Scaffold(
// TODO: Add a drawer instead of nav rail. appBar: AppBar(title: Text("Expense Tracker")),
body: Row( drawer: NavigationRail(
children: [
SafeArea(
child: NavigationRail(
extended: constraints.maxWidth >= 800, extended: constraints.maxWidth >= 800,
destinations: [ destinations: [
NavigationRailDestination( NavigationRailDestination(
@ -100,7 +103,7 @@ class _HomePageState extends State<HomePage> {
), ),
NavigationRailDestination( NavigationRailDestination(
icon: Icon(Icons.bar_chart), icon: Icon(Icons.bar_chart),
label: Text('Projections'), label: Text('Reports'),
), ),
NavigationRailDestination( NavigationRailDestination(
icon: Icon(Icons.settings), icon: Icon(Icons.settings),
@ -111,18 +114,16 @@ class _HomePageState extends State<HomePage> {
onDestinationSelected: (value) { onDestinationSelected: (value) {
setState(() { setState(() {
pageSelected = value; pageSelected = value;
Navigator.pop(context);
}); });
}, },
), ),
), body: Center(
Expanded(
child: Container( child: Container(
color: Theme.of(context).colorScheme.primaryContainer, color: Theme.of(context).colorScheme.primaryContainer,
child: page, child: page,
), ),
), ),
],
),
floatingActionButton: floatingButton, 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 { class ExpenseInputDialog extends StatefulWidget {
final Function() notifyParent;
const ExpenseInputDialog({ const ExpenseInputDialog({
super.key, super.key,
required this.notifyParent,
}); });
@override @override
@ -70,9 +59,6 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const inputWidth = 300.0;
const inputHeight = 50.0;
List<DropdownMenuItem> freqValues = []; List<DropdownMenuItem> freqValues = [];
for (var freq in Frequency.values) { for (var freq in Frequency.values) {
freqValues.add(DropdownMenuItem(value: freq, child: Text(freq.title))); 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")), title: Center(child: Text("Add New Expense")),
content: Form( content: Form(
key: _expenseFormKey, key: _expenseFormKey,
autovalidateMode: AutovalidateMode.onUserInteraction, //autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [
SizedBox( TextFormField(
width: inputWidth,
height: inputHeight,
child: TextFormField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Name", labelText: "Name",
@ -104,14 +87,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_name = newValue!; _name = newValue!;
}, },
), ),
), TextFormField(
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true), keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration( decoration:
labelText: "Cost", hintText: "Example: 10.00"), InputDecoration(labelText: "Cost", hintText: "Example: 10.00"),
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return "Cost must be provided."; return "Cost must be provided.";
@ -125,11 +104,7 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_cost = double.parse(newValue!); _cost = double.parse(newValue!);
}, },
), ),
), DropdownButtonFormField(
SizedBox(
width: inputWidth,
height: inputHeight,
child: DropdownButtonFormField(
items: freqValues, items: freqValues,
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Recurrence", hintText: "Example: Monthly"), labelText: "Recurrence", hintText: "Example: Monthly"),
@ -146,11 +121,7 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_freq = newValue; _freq = newValue;
}, },
), ),
), TextFormField(
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextFormField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Description", labelText: "Description",
@ -162,14 +133,10 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_desc = newValue!; _desc = newValue!;
}, },
), ),
),
]), ]),
), ),
actions: [ actions: [
SizedBox( Row(
width: inputWidth,
height: inputHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
@ -195,6 +162,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
description: _desc), description: _desc),
); );
}); });
widget.notifyParent();
print(expenses.toString()); print(expenses.toString());
for (var expense in expenses) { for (var expense in expenses) {
print(expense.toString()); print(expense.toString());
@ -206,7 +175,6 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
label: Text('Submit'), label: Text('Submit'),
), ),
], ],
),
) )
], ],
); );