diff --git a/lib/api/apis/goal_api.dart b/lib/api/apis/goal_api.dart index 8f16714..0474470 100644 --- a/lib/api/apis/goal_api.dart +++ b/lib/api/apis/goal_api.dart @@ -20,6 +20,7 @@ class GoalApi { Future createGoal( {required final String name, + required final String? description, required final double amount, required final DateTime date, required final double targetAmount, @@ -29,6 +30,7 @@ class GoalApi { return _db.into(_db.goalTable).insert(GoalTableCompanion.insert( name: name, amount: amount, + description: Value(description), date: date, targetAmount: targetAmount, targetDate: targetDate, @@ -39,6 +41,7 @@ class GoalApi { Future update( {required final int id, required final String name, + required final String? description, required final double amount, required final DateTime date, required final double targetAmount, @@ -48,6 +51,7 @@ class GoalApi { return (_db.update(_db.goalTable)..where((t) => t.id.equals(id))).write( GoalTableCompanion( name: Value(name), + description: Value(description), amount: Value(amount), date: Value(date), targetAmount: Value(targetAmount), diff --git a/lib/api/apis/investment_api.dart b/lib/api/apis/investment_api.dart index 00cea4d..bc735c8 100644 --- a/lib/api/apis/investment_api.dart +++ b/lib/api/apis/investment_api.dart @@ -34,6 +34,7 @@ class InvestmentApi { Future createInvestment({ required final String name, + required final String? description, required final int? basketId, required final RiskLevel riskLevel, required final double value, @@ -42,6 +43,7 @@ class InvestmentApi { return _db.into(_db.investmentTable).insert(InvestmentTableCompanion.insert( name: name, basketId: Value(basketId), + description: Value(description), value: value, riskLevel: riskLevel, valueUpdatedOn: valueUpdatedAt)); @@ -49,11 +51,13 @@ class InvestmentApi { Future createTransaction( {required final int investmentId, + required final String? description, required final double amount, required final DateTime date}) async { return _db.into(_db.transactionTable).insert( TransactionTableCompanion.insert( investmentId: investmentId, + description: Value(description), amount: amount, amountInvestedOn: date)); } @@ -66,6 +70,7 @@ class InvestmentApi { Future updateInvestment({ required final int id, required final String name, + required final String? description, required final int? basketId, required final RiskLevel riskLevel, required final double value, @@ -74,6 +79,7 @@ class InvestmentApi { return (_db.update(_db.investmentTable)..where((t) => t.id.equals(id))) .write(InvestmentTableCompanion( name: Value(name), + description: Value(description), basketId: Value(basketId), riskLevel: Value(riskLevel), value: Value(value), @@ -83,11 +89,13 @@ class InvestmentApi { Future updateTransaction( {required final int id, required final int investmentId, + required final String? description, required final double amount, required final DateTime date}) async { return (_db.update(_db.transactionTable)..where((t) => t.id.equals(id))) .write(TransactionTableCompanion( investmentId: Value(investmentId), + description: Value(description), amount: Value(amount), amountInvestedOn: Value(date), )); diff --git a/lib/presentation/create_goal_presenter.dart b/lib/presentation/create_goal_presenter.dart index 6d80cdd..982455f 100644 --- a/lib/presentation/create_goal_presenter.dart +++ b/lib/presentation/create_goal_presenter.dart @@ -22,6 +22,7 @@ class CreateGoalPresenter extends Presenter { } final name = viewState.name; + final description = viewState.description; final amount = viewState.amount; final date = viewState.date; final targetAmount = viewState.getTargetAmount(); @@ -34,6 +35,7 @@ class CreateGoalPresenter extends Presenter { .update( id: goalIdToUpdate, name: name, + description: description, amount: amount, date: date, targetAmount: targetAmount, @@ -46,6 +48,7 @@ class CreateGoalPresenter extends Presenter { _goalApi .createGoal( name: name, + description: description, amount: amount, date: date, targetAmount: targetAmount, @@ -61,6 +64,10 @@ class CreateGoalPresenter extends Presenter { updateViewState((viewState) => viewState.name = text); } + void descriptionChanged(String text) { + updateViewState((viewState) => viewState.description = text); + } + void amountChanged(String text) { updateViewState( (viewState) => viewState.amount = double.tryParse(text) ?? 0); @@ -85,6 +92,7 @@ class CreateGoalPresenter extends Presenter { void setGoal(Goal goalToUpdate) { updateViewState((viewState) { viewState.name = goalToUpdate.name; + viewState.description = goalToUpdate.description; viewState.amount = goalToUpdate.amount; viewState.inflation = goalToUpdate.inflation; viewState.importance = goalToUpdate.importance; @@ -96,6 +104,7 @@ class CreateGoalPresenter extends Presenter { class CreateGoalViewState { String name = ''; + String? description; double amount = 0.0; DateTime date = DateTime.now(); DateTime targetDate = DateTime.now().add(const Duration(days: 365)); diff --git a/lib/presentation/create_investment_presenter.dart b/lib/presentation/create_investment_presenter.dart index 40c7154..ba065a8 100644 --- a/lib/presentation/create_investment_presenter.dart +++ b/lib/presentation/create_investment_presenter.dart @@ -31,6 +31,7 @@ class CreateInvestmentPresenter extends Presenter { } final name = viewState.name; + final description = viewState.description; final value = viewState.value; final valueUpdatedAt = viewState._getValueUpdatedAt(); final basketId = viewState.basketId; @@ -40,6 +41,7 @@ class CreateInvestmentPresenter extends Presenter { _investmentApi .updateInvestment( id: investmentIdToUpdate, + description: description, name: name, value: value, valueUpdatedAt: valueUpdatedAt, @@ -51,6 +53,7 @@ class CreateInvestmentPresenter extends Presenter { _investmentApi .createInvestment( name: name, + description: description, value: value, valueUpdatedAt: valueUpdatedAt, basketId: basketId, @@ -64,6 +67,10 @@ class CreateInvestmentPresenter extends Presenter { updateViewState((viewState) => viewState.name = text); } + void descriptionChanged(String text) { + updateViewState((viewState) => viewState.description = text); + } + void valueChanged(String text) { updateViewState( (viewState) => viewState.value = double.tryParse(text) ?? 0); @@ -94,6 +101,7 @@ class CreateInvestmentPresenter extends Presenter { class CreateInvestmentViewState { String name = ''; + String? description; int? basketId; RiskLevel riskLevel = RiskLevel.medium; double value = 0.0; @@ -102,10 +110,10 @@ class CreateInvestmentViewState { List baskets = List.empty(growable: false); bool isValid() { - return name.isNotEmpty && - value > 0 && - isValidDate(valueUpdatedAt) && - basketId != null; + return name.isNotEmpty && + value > 0 && + isValidDate(valueUpdatedAt) && + basketId != null; } DateTime _getValueUpdatedAt() { diff --git a/lib/presentation/create_transaction_presenter.dart b/lib/presentation/create_transaction_presenter.dart index 3081eca..aec81a4 100644 --- a/lib/presentation/create_transaction_presenter.dart +++ b/lib/presentation/create_transaction_presenter.dart @@ -22,6 +22,7 @@ class CreateTransactionPresenter extends Presenter { return; } + final description = viewState.description; final amount = viewState.amount; final investedDate = viewState.getInvestedDate(); @@ -29,6 +30,7 @@ class CreateTransactionPresenter extends Presenter { _investmentApi .updateTransaction( id: transactionIdToUpdate, + description: description, investmentId: investmentId, amount: amount, date: investedDate) @@ -37,12 +39,19 @@ class CreateTransactionPresenter extends Presenter { } else { _investmentApi .createTransaction( - investmentId: investmentId, amount: amount, date: investedDate) + investmentId: investmentId, + description: description, + amount: amount, + date: investedDate) .then((_) => updateViewState((viewState) => viewState.onTransactionCreated = SingleEvent(null))); } } + void onDescriptionChanged(String text) { + updateViewState((viewState) => viewState.description = text); + } + void onAmountChanged(String text) { updateViewState( (viewState) => viewState.amount = double.tryParse(text) ?? 0); @@ -61,6 +70,7 @@ class CreateTransactionPresenter extends Presenter { } class CreateTransactionViewState { + String? description; double amount = 0.0; String investedDate = formatDate(DateTime.now()); SingleEvent? onTransactionCreated; diff --git a/lib/ui/widgets/create_goal_dialog.dart b/lib/ui/widgets/create_goal_dialog.dart index 67235e4..1418085 100644 --- a/lib/ui/widgets/create_goal_dialog.dart +++ b/lib/ui/widgets/create_goal_dialog.dart @@ -27,6 +27,7 @@ class _CreateGoalDialog extends StatefulWidget { class _CreateGoalPage extends PageState { final _nameController = TextEditingController(); + final _descriptionController = TextEditingController(); final _amountController = TextEditingController(); final _currentDateController = TextEditingController(); final _inflationController = TextEditingController(); @@ -39,6 +40,7 @@ class _CreateGoalPage extends PageState { final _nameController = TextEditingController(); + final _descriptionController = TextEditingController(); final _valueController = TextEditingController(); final _valueUpdatedDateController = TextEditingController(); @@ -38,6 +39,7 @@ class _CreateInvestmentPage extends PageState { + final _descriptionController = TextEditingController(); final _valueController = TextEditingController(); final _valueUpdatedDateController = TextEditingController(); @@ -40,19 +41,23 @@ class _CreateTransactionPage extends PageState[ + TextFormField( + textInputAction: TextInputAction.next, + controller: _descriptionController, + decoration: const InputDecoration( + labelText: 'Description', border: OutlineInputBorder()), + ), TextFormField( textInputAction: TextInputAction.next, controller: _valueController,