This commit is contained in:
2024-02-10 13:11:28 +01:00
parent f1e35670d2
commit 6e41e1a309
+30 -4
View File
@@ -34,6 +34,35 @@ class _NewExpenseState extends State<NewExpense> {
});
}
void _submitExpenseData() {
final enteredAmount = double.tryParse(_amountController.text);
final amountIsInvalid = enteredAmount == null || enteredAmount <= 0;
if (_titleController.text.trim().isEmpty ||
amountIsInvalid ||
_selectedCategory == null) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Invalid input'),
content: const Text(
'Please make sure a valid title, amount date and category was entered.'),
actions: [
TextButton(
onPressed: () {
Navigator.pop(ctx);
},
child: const Text('Okay'),
),
],
),
);
return;
}
// ...
}
@override
void dispose() {
_titleController.dispose();
@@ -118,10 +147,7 @@ class _NewExpenseState extends State<NewExpense> {
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () {
print(_titleController.text);
print(_amountController.text);
},
onPressed: _submitExpenseData,
child: const Text('Save Expense'),
),
],