diff --git a/lib/pages/expense.dart b/lib/pages/expense.dart index 2a383c1..37b2941 100644 --- a/lib/pages/expense.dart +++ b/lib/pages/expense.dart @@ -63,82 +63,83 @@ class _ExpenseInputDialogState extends State { @override Widget build(BuildContext context) { - // TODO: Do this as a values.map(). - List freqValues = []; - for (var freq in Frequency.values) { - freqValues.add(DropdownMenuItem(value: freq, child: Text(freq.title))); - } - ; - return AlertDialog( - title: Center(child: Text("Add New Expense")), + title: Center( + child: Text("Add New Expense"), + ), content: Form( key: _expenseFormKey, //autovalidateMode: AutovalidateMode.onUserInteraction, - child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ - TextFormField( - keyboardType: TextInputType.text, - decoration: InputDecoration( - labelText: "Name", - hintText: "Example: Red Pocket Phone Bill", + child: Column( + mainAxisSize: MainAxisSize.min, + //spacing: 10, + children: [ + TextFormField( + keyboardType: TextInputType.text, + decoration: InputDecoration( + labelText: "Name", + hintText: "Example: Red Pocket Phone Bill", + ), + validator: (value) { + if (value!.isEmpty) { + return "Name must be provided."; + } + return null; + }, + onSaved: (newValue) { + _name = newValue!; + }, ), - validator: (value) { - if (value!.isEmpty) { - return "Name must be provided."; - } - return null; - }, - onSaved: (newValue) { - _name = newValue!; - }, - ), - TextFormField( - keyboardType: TextInputType.numberWithOptions(decimal: true), - decoration: - InputDecoration(labelText: "Cost", hintText: "Example: 10.00"), - validator: (value) { - if (value!.isEmpty) { - return "Cost must be provided."; - } - if (double.tryParse(value) == null) { - return "Cost must be a valid number."; - } - return null; - }, - onSaved: (newValue) { - _cost = double.parse(newValue!); - }, - ), - DropdownButtonFormField( - items: freqValues, - decoration: InputDecoration( - labelText: "Recurrence", hintText: "Example: Monthly"), - validator: (value) { - if (value == null) { - return "Frequency must be provided."; - } - if (!Frequency.values.contains(value)) { - return "Value not valid."; - } - return null; - }, - onChanged: (newValue) { - _freq = newValue; - }, - ), - TextFormField( - keyboardType: TextInputType.text, - decoration: InputDecoration( - labelText: "Description", - hintText: "Example: 1GB data with unlimited talk & text."), - validator: (value) { - return null; - }, - onSaved: (newValue) { - _desc = newValue!; - }, - ), - ]), + TextFormField( + keyboardType: TextInputType.numberWithOptions(decimal: true), + decoration: InputDecoration( + labelText: "Cost", hintText: "Example: 10.00"), + validator: (value) { + if (value!.isEmpty) { + return "Cost must be provided."; + } + if (double.tryParse(value) == null) { + return "Cost must be a valid number."; + } + return null; + }, + onSaved: (newValue) { + _cost = double.parse(newValue!); + }, + ), + DropdownButtonFormField( + items: (Frequency.values.map((freq) => + DropdownMenuItem(value: freq, child: Text(freq.title)))) + .toList(), + decoration: InputDecoration( + labelText: "Recurrence", hintText: "Example: Monthly"), + validator: (value) { + if (value == null) { + return "Frequency must be provided."; + } + if (!Frequency.values.contains(value)) { + return "Value not valid."; + } + return null; + }, + onChanged: (newValue) { + _freq = newValue!; + }, + ), + TextFormField( + keyboardType: TextInputType.text, + decoration: InputDecoration( + labelText: "Description", + hintText: "Example: 1GB data with unlimited talk & text."), + validator: (value) { + return null; + }, + onSaved: (newValue) { + _desc = newValue!; + }, + ), + ], + ), ), actions: [ Row( @@ -147,7 +148,6 @@ class _ExpenseInputDialogState extends State { children: [ ElevatedButton.icon( onPressed: () { - print("TODO: Clear fields!"); Navigator.of(context).pop(); }, icon: Icon(Icons.cancel), @@ -155,7 +155,6 @@ class _ExpenseInputDialogState extends State { ), ElevatedButton.icon( onPressed: () { - print("TODO: Save expense!"); if (_expenseFormKey.currentState!.validate()) { _expenseFormKey.currentState!.save(); setState(() { @@ -168,11 +167,6 @@ class _ExpenseInputDialogState extends State { ); }); widget.notifyParent(); - - print(expenses.toString()); - for (var expense in expenses) { - print(expense.toString()); - } Navigator.of(context).pop(); } },