Redo how the frequencies are generated. Clean up old print statements.

This commit is contained in:
Hyperling 2025-02-05 16:41:58 -07:00
parent 5561f50736
commit 66fd966de8

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