Skip to content

Commit

Permalink
Merge pull request #89 from enrique-lozano/hot-fixes
Browse files Browse the repository at this point in the history
Some dialogs returning to a black screen
  • Loading branch information
enrique-lozano authored Dec 1, 2023
2 parents cee6436 + 9ad5535 commit 79f2843
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 538 deletions.
178 changes: 74 additions & 104 deletions lib/app/accounts/account_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:monekin/core/models/transaction/transaction.dart';
import 'package:monekin/core/models/transaction/transaction_status.dart';
import 'package:monekin/core/presentation/widgets/bottomSheetFooter.dart';
import 'package:monekin/core/presentation/widgets/card_with_header.dart';
import 'package:monekin/core/presentation/widgets/confirm_dialog.dart';
import 'package:monekin/core/presentation/widgets/date_form_field/date_form_field.dart';
import 'package:monekin/core/presentation/widgets/inline_info_card.dart';
import 'package:monekin/core/presentation/widgets/monekin_quick_actions_buttons.dart';
Expand Down Expand Up @@ -53,23 +54,13 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
onClick: account.isClosed
? null
: () async {
showAccountsWarn() => showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
t.transfer.need_two_accounts_warning_header),
content: SingleChildScrollView(
child: Text(t.transfer
.need_two_accounts_warning_message)),
actions: [
TextButton(
child: Text(t.general.understood),
onPressed: () => Navigator.pop(context)),
],
);
},
);
showAccountsWarn() async =>
await showConfirmDialog(context,
dialogTitle:
t.transfer.need_two_accounts_warning_header,
contentParagraphs: [
Text(t.transfer.need_two_accounts_warning_message)
]);

navigateToTransferForm() => context.pushRoute(
TransactionFormRoute(
Expand All @@ -78,9 +69,13 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
),
);

final numberOfAccounts =
(await AccountService.instance.getAccounts().first)
.length;
final numberOfAccounts = (await AccountService.instance
.getAccounts(
predicate: (acc, curr) =>
acc.closingDate.isNotNull(),
)
.first)
.length;

if (numberOfAccounts <= 1) {
await showAccountsWarn();
Expand Down Expand Up @@ -112,59 +107,43 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
label: t.general.delete,
icon: Icons.delete,
role: ListTileActionRole.delete,
onClick: () => deleteTransactionWithAlertAndSnackBar(
context,
transactionId: account.id,
navigateBack: navigateBackOnDelete,
)),
onClick: () {
deleteAccountWithAlertAndSnackBar(
context,
accountId: account.id,
navigateBack: navigateBackOnDelete,
);
}),
];
}

showReopenAccountDialog(Account account) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(t.account.reopen),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text(t.account.reopen_descr)],
),
showConfirmDialog(
context,
showCancelButton: true,
dialogTitle: t.account.reopen,
contentParagraphs: [
Text(t.account.reopen_descr),
],
confirmationText: t.general.confirm,
).then((isConfirmed) {
AccountService.instance
.updateAccount(
account.copyWith(
closingDate: const drift.Value(null),
),
actions: [
TextButton(
child: Text(t.general.cancel),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text(t.general.confirm),
onPressed: () {
AccountService.instance
.updateAccount(
account.copyWith(
closingDate: const drift.Value(null),
),
)
.then((value) {
if (value) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(t.account.close.unarchive_succes)),
);
}
})
.whenComplete(() => Navigator.pop(context))
.catchError((err) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$err')));
});
},
),
],
),
);
)
.then((value) {
if (value) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(t.account.close.unarchive_succes)),
);
}
}).catchError((err) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$err')));
});
});
}

Future<bool?> showCloseAccountDialog(Account account, double currentBalance) {
Expand All @@ -177,42 +156,33 @@ class _AccountDetailsPageState extends State<AccountDetailsPage> {
);
}

deleteTransactionWithAlertAndSnackBar(BuildContext context,
{required String transactionId, required bool navigateBack}) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(t.account.delete.warning_header),
content:
SingleChildScrollView(child: Text(t.account.delete.warning_text)),
actions: [
TextButton(
child: Text(t.general.confirm),
onPressed: () {
AccountService.instance
.deleteAccount(transactionId)
.then((value) {
Navigator.pop(context);

if (navigateBack) {
Navigator.pop(context);
}

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(t.account.delete.success)));
}).catchError((err) {
Navigator.pop(context);

ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$err')));
});
},
),
],
);
},
);
deleteAccountWithAlertAndSnackBar(
BuildContext context, {
required String accountId,
required bool navigateBack,
}) {
final scaffold = ScaffoldMessenger.of(context);

showConfirmDialog(
context,
dialogTitle: t.account.delete.warning_header,
contentParagraphs: [Text(t.account.delete.warning_text)],
confirmationText: t.general.continue_text,
showCancelButton: true,
).then((isConfirmed) {
if (isConfirmed != true) return;

AccountService.instance.deleteAccount(accountId).then((value) {
if (navigateBack) {
Navigator.pop(context);
}

scaffold
.showSnackBar(SnackBar(content: Text(t.account.delete.success)));
}).catchError((err) {
scaffold.showSnackBar(SnackBar(content: Text('$err')));
});
});
}

ListTile buildCopyableTile(String title, String value) {
Expand Down
54 changes: 24 additions & 30 deletions lib/app/budgets/budget_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:monekin/core/models/transaction/transaction_status.dart';
import 'package:monekin/core/presentation/theme.dart';
import 'package:monekin/core/presentation/widgets/animated_progress_bar.dart';
import 'package:monekin/core/presentation/widgets/card_with_header.dart';
import 'package:monekin/core/presentation/widgets/confirm_dialog.dart';
import 'package:monekin/core/presentation/widgets/monekin_popup_menu_button.dart';
import 'package:monekin/core/presentation/widgets/number_ui_formatters/currency_displayer.dart';
import 'package:monekin/core/presentation/widgets/skeleton.dart';
Expand Down Expand Up @@ -72,6 +73,8 @@ class _BudgetDetailsPageState extends State<BudgetDetailsPage> {
stream: BudgetServive.instance.getBudgetById(widget.budget.id),
initialData: widget.budget,
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();

final budget = snapshot.data!;

return DefaultTabController(
Expand Down Expand Up @@ -101,37 +104,28 @@ class _BudgetDetailsPageState extends State<BudgetDetailsPage> {
label: t.general.delete,
icon: Icons.delete,
role: ListTileActionRole.delete,
onClick: () async {
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(t.budgets.delete),
content: Text(t.budgets.delete_warning),
actions: [
TextButton(
child: Text(t.general.confirm),
onPressed: () {
BudgetServive.instance
.deleteBudget(budget.id)
.then((value) {
Navigator.pop(context);
onClick: () {
showConfirmDialog(
context,
dialogTitle: t.budgets.delete,
contentParagraphs: [Text(t.budgets.delete_warning)],
confirmationText: t.general.confirm,
).then((confirmed) {
if (confirmed != true) return;

ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(
content: Text(t.general.delete)));
}).catchError((err) {
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(content: Text('$err')));
}).whenComplete(
() => Navigator.pop(context));
},
),
],
);
},
);
BudgetServive.instance
.deleteBudget(budget.id)
.then((value) {
Navigator.pop(context);

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(t.budgets.delete),
));
}).catchError((err) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$err')));
});
});
},
)
])
Expand Down
Loading

0 comments on commit 79f2843

Please sign in to comment.