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

View File

@ -63,19 +63,17 @@ 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(
mainAxisSize: MainAxisSize.min,
//spacing: 10,
children: [
TextFormField( TextFormField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: InputDecoration( decoration: InputDecoration(
@ -94,8 +92,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
), ),
TextFormField( TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true), keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: decoration: InputDecoration(
InputDecoration(labelText: "Cost", hintText: "Example: 10.00"), labelText: "Cost", hintText: "Example: 10.00"),
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return "Cost must be provided."; return "Cost must be provided.";
@ -110,7 +108,9 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
}, },
), ),
DropdownButtonFormField( DropdownButtonFormField(
items: freqValues, items: (Frequency.values.map((freq) =>
DropdownMenuItem(value: freq, child: Text(freq.title))))
.toList(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: "Recurrence", hintText: "Example: Monthly"), labelText: "Recurrence", hintText: "Example: Monthly"),
validator: (value) { validator: (value) {
@ -123,7 +123,7 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
return null; return null;
}, },
onChanged: (newValue) { onChanged: (newValue) {
_freq = newValue; _freq = newValue!;
}, },
), ),
TextFormField( TextFormField(
@ -138,7 +138,8 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
_desc = 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();
} }
}, },