Skip to content

Commit

Permalink
save commit
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 20, 2024
1 parent 4b2f0db commit 42cab04
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 28 deletions.
2 changes: 2 additions & 0 deletions lib/presentation/create_basket_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CreateBasketPresenter extends Presenter<CreateBasketViewState> {
updateViewState((viewState) {
viewState.name = basketToUpdate.name;
viewState.description = basketToUpdate.description ?? '';
viewState.onBasketFetched = SingleEvent(null);
});
}
}
Expand All @@ -59,6 +60,7 @@ class CreateBasketViewState {
String name = '';
String description = '';
SingleEvent<void>? onBasketCreated;
SingleEvent<void>? onBasketFetched;

bool isValid() {
return name.isNotEmpty;
Expand Down
7 changes: 5 additions & 2 deletions lib/presentation/create_investment_transaction_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ class CreateInvestmentTransactionPresenter
updateViewState((viewState) => viewState.investedDate = date);
}

void setTransaction(Transaction transactionToUpdate) {
void _setTransaction(Transaction transactionToUpdate) {
updateViewState((viewState) {
viewState.amount = transactionToUpdate.amount;
viewState.investedDate = transactionToUpdate.createdOn;
viewState.description = transactionToUpdate.description ?? '';
viewState.onTransactionLoaded = SingleEvent(null);
});
}

void fetchTransaction({required int id}) {
_transactionService
.getBy(id: id)
.then((transaction) => setTransaction(transaction));
.then((transaction) => _setTransaction(transaction));
}
}

Expand All @@ -83,6 +85,7 @@ class CreateTransactionViewState {
double amount = 0;
DateTime investedDate = DateTime.now();
SingleEvent<void>? onTransactionCreated;
SingleEvent<void>? onTransactionLoaded;

bool isValid() {
return amount > 0;
Expand Down
6 changes: 4 additions & 2 deletions lib/presentation/create_sip_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,19 @@ class CreateSipPresenter extends Presenter<CreateSipViewState> {
updateViewState((viewState) => viewState.frequency = frequency);
}

void setSip(SIP sipToUpdate) {
void _setSip(SIP sipToUpdate) {
updateViewState((viewState) {
viewState.description = sipToUpdate.description ?? '';
viewState.amount = sipToUpdate.amount;
viewState.startDate = sipToUpdate.startDate;
viewState.endDate = sipToUpdate.endDate;
viewState.frequency = sipToUpdate.frequency;
viewState.onSipLoaded = SingleEvent(null);
});
}

void fetchSip({required int id}) {
_sipService.getBy(id: id).then((sip) => setSip(sip));
_sipService.getBy(id: id).then((sip) => _setSip(sip));
}
}

Expand All @@ -100,6 +101,7 @@ class CreateSipViewState {
DateTime? endDate = DateTime.now().add(const Duration(days: 365));
SipFrequency frequency = SipFrequency.monthly;
SingleEvent<void>? onSipCreated;
SingleEvent<void>? onSipLoaded;

bool isValid() {
final endDate = this.endDate;
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/investments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class _InvestmentsPage extends PageState<InvestmentsViewState, InvestmentsPage,
children: [
Text(formatToPercentage(investmentVO.irr),
style: Theme.of(context).textTheme.bodyMedium),
Text('(Growth Per Yearl)',
Text('(Growth Per Year)',
style: Theme.of(context).textTheme.labelSmall),
],
),
Expand Down
8 changes: 8 additions & 0 deletions lib/ui/widgets/create_basket_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class _CreateBasketPage extends PageState<CreateBasketViewState,
void initState() {
super.initState();

final viewState = presenter.getViewState();
_nameController.text = viewState.name;
_descriptionController.text = viewState.description;

int? basketIdToUpdate = widget.basketIdTOUpdate;
if (basketIdToUpdate != null) {
presenter.fetchBasket(id: basketIdToUpdate);
Expand All @@ -49,6 +53,10 @@ class _CreateBasketPage extends PageState<CreateBasketViewState,
snapshot.onBasketCreated?.consume((_) {
Navigator.of(context).pop();
});
snapshot.onBasketFetched?.consume((_) {
_nameController.text = snapshot.name;
_descriptionController.text = snapshot.description;
});
});

return AlertDialog(
Expand Down
33 changes: 20 additions & 13 deletions lib/ui/widgets/create_goal_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
void initState() {
super.initState();

final viewState = presenter.getViewState();
_nameController.text = viewState.name;
_descriptionController.text = viewState.description;
_amountController.text = formatToCurrency(viewState.amount);
_currentDateController.text = formatDate(viewState.date);
_targetDateController.text = formatDate(viewState.targetDate);
_inflationController.text = viewState.inflation.toString();

int? goalIdToUpdate = widget.goalIdToUpdate;
if (goalIdToUpdate != null) {
presenter.fetchGoal(id: goalIdToUpdate);
} else {
_currentDateController.text = formatDate(DateTime.now());
_targetDateController.text =
formatDate(DateTime.now().add(const Duration(days: 365)));
}

_nameController.addListener(() {
Expand Down Expand Up @@ -80,6 +84,15 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
snapshot.onGoalCreated?.consume((_) {
Navigator.of(context).pop();
});

snapshot.onDataLoaded?.consume((_) {
_nameController.text = snapshot.name;
_descriptionController.text = snapshot.description;
_amountController.text = formatToCurrency(snapshot.amount);
_currentDateController.text = formatDate(snapshot.date);
_targetDateController.text = formatDate(snapshot.targetDate);
_inflationController.text = snapshot.inflation.toString();
});
});

return AlertDialog(
Expand Down Expand Up @@ -117,29 +130,23 @@ class _CreateGoalPage extends PageState<CreateGoalViewState, _CreateGoalDialog,
textInputAction: TextInputAction.next,
controller: _amountController,
keyboardType: TextInputType.number,
inputFormatters: [
CurrencyTextInputFormatter()
],
inputFormatters: [CurrencyTextInputFormatter()],
decoration: const InputDecoration(
labelText: 'Amount', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _currentDateController,
inputFormatters: [
DateTextInputFormatter()
],
inputFormatters: [DateTextInputFormatter()],
decoration: const InputDecoration(
labelText: 'Date (DD/MM/YYYY)', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _targetDateController,
inputFormatters: [
DateTextInputFormatter()
],
inputFormatters: [DateTextInputFormatter()],
decoration: const InputDecoration(
labelText: 'Target Date (DD/MM/YYYY)',
border: OutlineInputBorder()),
Expand Down
8 changes: 8 additions & 0 deletions lib/ui/widgets/create_investment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
void initState() {
super.initState();

final viewState = presenter.getViewState();
_nameController.text = viewState.name;
_descriptionController.text = viewState.description;
_irrController.text = viewState.irr?.toString() ?? '';
_valueController.text = viewState.value?.toString() ?? '';
_valueUpdatedDateController.text =
viewState.valueUpdatedAt != null ? formatDate(viewState.valueUpdatedAt!) : '';

int? investmentIdToUpdate = widget.investmentIdToUpdate;
if (investmentIdToUpdate != null) {
presenter.fetchInvestment(id: investmentIdToUpdate);
Expand Down
14 changes: 14 additions & 0 deletions lib/ui/widgets/create_sip_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class _CreateTransactionPage extends PageState<CreateSipViewState,
void initState() {
super.initState();

final viewState = presenter.getViewState();
_valueController.text = formatToCurrency(viewState.amount);
_descriptionController.text = viewState.description;
_startDateController.text = formatDate(viewState.startDate);
_endDateController.text =
viewState.endDate != null ? formatDate(viewState.endDate!) : '';

int? sipIdToUpdate = widget.sipIdToUpdate;
if (sipIdToUpdate != null) {
presenter.fetchSip(id: sipIdToUpdate);
Expand All @@ -66,6 +73,13 @@ class _CreateTransactionPage extends PageState<CreateSipViewState,
snapshot.onSipCreated?.consume((_) {
Navigator.of(context).pop();
});
snapshot.onSipLoaded?.consume((_) {
_valueController.text = formatToCurrency(snapshot.amount);
_descriptionController.text = snapshot.description;
_startDateController.text = formatDate(snapshot.startDate);
_endDateController.text =
snapshot.endDate != null ? formatDate(snapshot.endDate!) : '';
});
});

return AlertDialog(
Expand Down
14 changes: 11 additions & 3 deletions lib/ui/widgets/create_transaction_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class _CreateTransactionPage extends PageState<CreateTransactionViewState,
void initState() {
super.initState();

final viewState = presenter.getViewState();
_valueController.text = formatToCurrency(viewState.amount);
_descriptionController.text = viewState.description;
_valueUpdatedDateController.text = formatDate(viewState.investedDate);

int? transactionIdToUpdate = widget._transactionIdToUpdate;
if (transactionIdToUpdate != null) {
presenter.fetchTransaction(id: transactionIdToUpdate);
Expand All @@ -71,6 +76,11 @@ class _CreateTransactionPage extends PageState<CreateTransactionViewState,
snapshot.onTransactionCreated?.consume((_) {
Navigator.of(context).pop();
});
snapshot.onTransactionLoaded?.consume((_) {
_descriptionController.text = snapshot.description;
_valueController.text = formatToCurrency(snapshot.amount);
_valueUpdatedDateController.text = formatDate(snapshot.investedDate);
});
});

return AlertDialog(
Expand Down Expand Up @@ -117,9 +127,7 @@ class _CreateTransactionPage extends PageState<CreateTransactionViewState,
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueUpdatedDateController,
inputFormatters: [
DateTextInputFormatter()
],
inputFormatters: [DateTextInputFormatter()],
decoration: const InputDecoration(
labelText: 'Date (DD/MM/YYYY)', border: OutlineInputBorder()),
),
Expand Down
22 changes: 15 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -362,18 +362,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -715,6 +715,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -756,5 +764,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.6 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.10.0"

0 comments on commit 42cab04

Please sign in to comment.