From e5e85b68ff62eb6552164220692edd3b34d5c7da Mon Sep 17 00:00:00 2001 From: Hyperling Date: Fri, 7 Mar 2025 13:06:26 -0700 Subject: [PATCH] Income and Assets are successfully being inserted and selected! Still needs tweaking, such as Asset saying "monthly". --- lib/pages/tracked_item.dart | 150 +++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 53 deletions(-) diff --git a/lib/pages/tracked_item.dart b/lib/pages/tracked_item.dart index 85f465c..8a6dc1e 100644 --- a/lib/pages/tracked_item.dart +++ b/lib/pages/tracked_item.dart @@ -331,7 +331,7 @@ class _TrackedItemInputDialogState extends State { title: Center( child: widget.entry == null ? Text("New ${_type!.title}") - : Text("Edit Expense"), + : Text("Edit ${_type!.title}"), ), content: FutureBuilder>( future: DatabaseHelper.instance.getExpenses(), @@ -399,46 +399,47 @@ class _TrackedItemInputDialogState extends State { _amount = double.parse(value!); }, ), - DropdownButtonFormField( - items: Frequency.values - .map( - (freq) => DropdownMenuItem( - value: freq, - child: Row( - children: [ - Text( - freq.title, - ), - Padding( - padding: EdgeInsets.all(1.0), - child: Text( - " (${freq.hint})", - style: TextStyle(fontSize: 10.0), + if (_type != ItemType.asset) + DropdownButtonFormField( + items: Frequency.values + .map( + (freq) => DropdownMenuItem( + value: freq, + child: Row( + children: [ + Text( + freq.title, ), - ), - ], + Padding( + padding: EdgeInsets.all(1.0), + child: Text( + " (${freq.hint})", + style: TextStyle(fontSize: 10.0), + ), + ), + ], + ), ), - ), - ) - .toList(), - value: _freq, - decoration: InputDecoration( - labelText: "Frequency", - errorStyle: TextStyle(fontSize: 10.0), + ) + .toList(), + value: _freq, + decoration: InputDecoration( + labelText: "Frequency", + errorStyle: TextStyle(fontSize: 10.0), + ), + validator: (value) { + if (value == null) { + return "Frequency must be provided."; + } + if (!Frequency.values.contains(value)) { + return "Value not valid."; + } + return null; + }, + onChanged: (value) { + _freq = value!; + }, ), - validator: (value) { - if (value == null) { - return "Frequency must be provided."; - } - if (!Frequency.values.contains(value)) { - return "Value not valid."; - } - return null; - }, - onChanged: (value) { - _freq = value!; - }, - ), TextFormField( keyboardType: TextInputType.text, textCapitalization: TextCapitalization.sentences, @@ -468,21 +469,64 @@ class _TrackedItemInputDialogState extends State { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); setState(() { - Expense expense = Expense( - id: _id, - name: _name, - amount: _amount, - frequency: _freq, - description: _desc, - ); - if (_id != null) { - DatabaseHelper.instance.updateExpense( - expense, - ); - } else { - DatabaseHelper.instance.addExpense( - expense, - ); + switch (_type) { + case ItemType.expense: + Expense expense = Expense( + id: _id, + name: _name, + amount: _amount, + frequency: _freq, + description: _desc, + ); + if (_id != null) { + DatabaseHelper.instance.updateExpense( + expense, + ); + } else { + DatabaseHelper.instance.addExpense( + expense, + ); + } + break; + case ItemType.income: + Income income = Income( + id: _id, + name: _name, + amount: _amount, + frequency: _freq, + description: _desc, + ); + if (_id != null) { + DatabaseHelper.instance.updateIncome( + income, + ); + } else { + DatabaseHelper.instance.addIncome( + income, + ); + } + break; + case ItemType.asset: + Asset asset = Asset( + id: _id, + name: _name, + amount: _amount, + description: _desc, + ); + if (_id != null) { + DatabaseHelper.instance.updateAsset( + asset, + ); + } else { + DatabaseHelper.instance.addAsset( + asset, + ); + } + break; + default: + throw UnimplementedError( + "No code for type ${_type!.title}", + ); } }); widget.notifyParent();