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,54 +179,61 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"), DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"),
]; ];
return Center( return AlertDialog(
child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ title: Text("Add New Expense"),
Text('New Expense'), content: Center(
SizedBox( child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [
Text('New Expense'),
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name",
hintText: "Example: Red Pocket Phone Bill",
),
// https://docs.flutter.dev/cookbook/forms/retrieve-input
//controller: nameFieldController,
)),
SizedBox(
width: inputWidth, width: inputWidth,
height: inputHeight, height: inputHeight,
child: TextField( child: TextField(
keyboardType: TextInputType.text, keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Name", labelText: "Cost", hintText: "Example: 10.00"),
hintText: "Example: Red Pocket Phone Bill", ),
),
// https://docs.flutter.dev/cookbook/forms/retrieve-input
//controller: nameFieldController,
)),
SizedBox(
width: inputWidth,
height: inputHeight,
child: TextField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration:
InputDecoration(labelText: "Cost", hintText: "Example: 10.00"),
), ),
), DropdownMenu(
DropdownMenu( dropdownMenuEntries: recurrenceValues,
dropdownMenuEntries: recurrenceValues,
width: inputWidth,
label: Text("Recurrence"),
hintText: "Example: Monthly",
),
SizedBox(
width: inputWidth, width: inputWidth,
height: inputHeight, label: Text("Recurrence"),
child: TextField( hintText: "Example: Monthly",
keyboardType: TextInputType.text, ),
decoration: InputDecoration( SizedBox(
labelText: "Description", width: inputWidth,
hintText: "Example: 1GB data with unlimited talk & text."), height: inputHeight,
)), child: TextField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Description",
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'),
), ),
], ],
)) ))
]), ],
); );
} }
} }