Buttons now close the dialog properly.
This commit is contained in:
parent
aa3c2f9304
commit
bcae40e0e2
@ -54,7 +54,7 @@ class _HomePageState extends State<HomePage> {
|
||||
switch (pageSelected) {
|
||||
case 0:
|
||||
page = ExpensePage();
|
||||
dialog = ExpenseInputForm();
|
||||
dialog = ExpenseInputDialog();
|
||||
case 1:
|
||||
page = IncomePage();
|
||||
case 2:
|
||||
@ -69,10 +69,7 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
Future<void> addNewValue(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) =>
|
||||
AlertDialog(title: Text("Add New Value"), content: dialog)
|
||||
);
|
||||
context: context, builder: (_) => AlertDialog(content: dialog));
|
||||
}
|
||||
|
||||
Widget? floatingButton;
|
||||
@ -159,16 +156,16 @@ class ExpensePage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class ExpenseInputForm extends StatefulWidget {
|
||||
const ExpenseInputForm({
|
||||
class ExpenseInputDialog extends StatefulWidget {
|
||||
const ExpenseInputDialog({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ExpenseInputForm> createState() => _ExpenseInputFormState();
|
||||
State<ExpenseInputDialog> createState() => _ExpenseInputDialogState();
|
||||
}
|
||||
|
||||
class _ExpenseInputFormState extends State<ExpenseInputForm> {
|
||||
class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const inputWidth = 300.0;
|
||||
@ -182,54 +179,61 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
|
||||
DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"),
|
||||
];
|
||||
|
||||
return Center(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [
|
||||
Text('New Expense'),
|
||||
SizedBox(
|
||||
return AlertDialog(
|
||||
title: Text("Add New Expense"),
|
||||
content: Center(
|
||||
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,
|
||||
height: inputHeight,
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.text,
|
||||
keyboardType: TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: "Name",
|
||||
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"),
|
||||
labelText: "Cost", hintText: "Example: 10.00"),
|
||||
),
|
||||
),
|
||||
),
|
||||
DropdownMenu(
|
||||
dropdownMenuEntries: recurrenceValues,
|
||||
width: inputWidth,
|
||||
label: Text("Recurrence"),
|
||||
hintText: "Example: Monthly",
|
||||
),
|
||||
SizedBox(
|
||||
DropdownMenu(
|
||||
dropdownMenuEntries: recurrenceValues,
|
||||
width: inputWidth,
|
||||
height: inputHeight,
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Description",
|
||||
hintText: "Example: 1GB data with unlimited talk & text."),
|
||||
)),
|
||||
label: Text("Recurrence"),
|
||||
hintText: "Example: Monthly",
|
||||
),
|
||||
SizedBox(
|
||||
width: inputWidth,
|
||||
height: inputHeight,
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Description",
|
||||
hintText: "Example: 1GB data with unlimited talk & text."),
|
||||
)),
|
||||
]),
|
||||
),
|
||||
actions: [
|
||||
SizedBox(
|
||||
width: inputWidth,
|
||||
height: inputHeight,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
print("TODO: Clear fields!");
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: Icon(Icons.cancel),
|
||||
label: Text('Cancel'),
|
||||
@ -237,13 +241,14 @@ class _ExpenseInputFormState extends State<ExpenseInputForm> {
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
print("TODO: Save expense!");
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: Icon(Icons.save),
|
||||
label: Text('Submit'),
|
||||
),
|
||||
],
|
||||
))
|
||||
]),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user