From 9d478b9cbfde27a452df5f3cc23a1acf7c725851 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Fri, 7 Feb 2025 05:10:22 -0700 Subject: [PATCH] Fix bug which sometimes set an edited expense to Monthly. Fix typo in enum `monthly`. --- lib/models/frequency.dart | 2 +- lib/pages/expense.dart | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/models/frequency.dart b/lib/models/frequency.dart index 7585b8c..8895ea6 100644 --- a/lib/models/frequency.dart +++ b/lib/models/frequency.dart @@ -20,7 +20,7 @@ enum Frequency { hint: "Twice Per Month", timesPerYear: 24, ), - montly( + monthly( title: "Monthly", hint: "Once Per Month", timesPerYear: 12, diff --git a/lib/pages/expense.dart b/lib/pages/expense.dart index 4993814..debe190 100644 --- a/lib/pages/expense.dart +++ b/lib/pages/expense.dart @@ -161,12 +161,19 @@ class _ExpenseInputDialogState extends State { final _expenseFormKey = GlobalKey(); String _name = ""; - double _cost = 0.0; - Frequency _freq = Frequency.montly; + double _cost = 0; + Frequency _freq = Frequency.monthly; String _desc = ""; @override Widget build(BuildContext context) { + if (widget.expense != null) { + _name = widget.expense!.name; + _cost = widget.expense!.cost; + _freq = widget.expense!.frequency; + _desc = widget.expense!.description; + } + return Column( // prevent AlertDialog from taking full vertical height. mainAxisSize: MainAxisSize.min, @@ -206,8 +213,7 @@ class _ExpenseInputDialogState extends State { hintStyle: TextStyle(fontSize: 10.0), errorStyle: TextStyle(fontSize: 10.0), ), - initialValue: - widget.expense == null ? "" : widget.expense!.name, + initialValue: _name, validator: (value) { if (value!.isEmpty) { return "Name must be provided."; @@ -229,9 +235,7 @@ class _ExpenseInputDialogState extends State { hintStyle: TextStyle(fontSize: 10.0), errorStyle: TextStyle(fontSize: 10.0), ), - initialValue: widget.expense == null - ? "" - : widget.expense!.cost.toString(), + initialValue: _cost != 0 ? _cost.toString() : "", validator: (value) { if (value == null || value.isEmpty) { return "Cost must be provided."; @@ -273,9 +277,7 @@ class _ExpenseInputDialogState extends State { ), ) .toList(), - value: widget.expense == null - ? Frequency.montly - : widget.expense!.frequency, + value: _freq, decoration: InputDecoration( labelText: "Frequency", errorStyle: TextStyle(fontSize: 10.0), @@ -301,8 +303,7 @@ class _ExpenseInputDialogState extends State { hintStyle: TextStyle(fontSize: 10.0), errorStyle: TextStyle(fontSize: 10.0), ), - initialValue: - widget.expense == null ? "" : widget.expense!.description, + initialValue: _desc, validator: (value) { return null; },