Buttons now close the dialog properly.

This commit is contained in:
Hyperling 2025-02-05 03:27:11 -07:00
parent aa3c2f9304
commit bcae40e0e2

View File

@ -54,7 +54,7 @@ class _HomePageState extends State<HomePage> {
switch (pageSelected) { switch (pageSelected) {
case 0: case 0:
page = ExpensePage(); page = ExpensePage();
dialog = ExpenseInputForm(); dialog = ExpenseInputDialog();
case 1: case 1:
page = IncomePage(); page = IncomePage();
case 2: case 2:
@ -69,10 +69,7 @@ class _HomePageState extends State<HomePage> {
Future<void> addNewValue(BuildContext context) { Future<void> addNewValue(BuildContext context) {
return showDialog( return showDialog(
context: context, context: context, builder: (_) => AlertDialog(content: dialog));
builder: (_) =>
AlertDialog(title: Text("Add New Value"), content: dialog)
);
} }
Widget? floatingButton; Widget? floatingButton;
@ -159,16 +156,16 @@ class ExpensePage extends StatelessWidget {
} }
} }
class ExpenseInputForm extends StatefulWidget { class ExpenseInputDialog extends StatefulWidget {
const ExpenseInputForm({ const ExpenseInputDialog({
super.key, super.key,
}); });
@override @override
State<ExpenseInputForm> createState() => _ExpenseInputFormState(); State<ExpenseInputDialog> createState() => _ExpenseInputDialogState();
} }
class _ExpenseInputFormState extends State<ExpenseInputForm> { class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const inputWidth = 300.0; const inputWidth = 300.0;
@ -182,7 +179,9 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"), DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"),
]; ];
return Center( return AlertDialog(
title: Text("Add New Expense"),
content: Center(
child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [
Text('New Expense'), Text('New Expense'),
SizedBox( SizedBox(
@ -202,8 +201,8 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
height: inputHeight, height: inputHeight,
child: TextField( child: TextField(
keyboardType: TextInputType.numberWithOptions(decimal: true), keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: decoration: InputDecoration(
InputDecoration(labelText: "Cost", hintText: "Example: 10.00"), labelText: "Cost", hintText: "Example: 10.00"),
), ),
), ),
DropdownMenu( DropdownMenu(
@ -221,15 +220,20 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
labelText: "Description", labelText: "Description",
hintText: "Example: 1GB data with unlimited talk & text."), hintText: "Example: 1GB data with unlimited talk & text."),
)), )),
]),
),
actions: [
SizedBox( SizedBox(
width: inputWidth, width: inputWidth,
height: inputHeight, height: inputHeight,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
ElevatedButton.icon( ElevatedButton.icon(
onPressed: () { onPressed: () {
print("TODO: Clear fields!"); print("TODO: Clear fields!");
Navigator.of(context).pop();
}, },
icon: Icon(Icons.cancel), icon: Icon(Icons.cancel),
label: Text('Cancel'), label: Text('Cancel'),
@ -237,13 +241,14 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
ElevatedButton.icon( ElevatedButton.icon(
onPressed: () { onPressed: () {
print("TODO: Save expense!"); print("TODO: Save expense!");
Navigator.of(context).pop();
}, },
icon: Icon(Icons.save), icon: Icon(Icons.save),
label: Text('Submit'), label: Text('Submit'),
), ),
], ],
)) ))
]), ],
); );
} }
} }