115 - 1
This commit is contained in:
@@ -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'),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user