Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icons in some confirmation dialogs #107

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/app/accounts/details/account_details_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AccountDetailsActions {
? null
: () async {
showAccountsWarn() async =>
await showConfirmDialog(context,
await confirmDialog(context,
dialogTitle:
t.transfer.need_two_accounts_warning_header,
contentParagraphs: [
Expand Down Expand Up @@ -95,7 +95,7 @@ abstract class AccountDetailsActions {
}

static showReopenAccountDialog(BuildContext context, Account account) {
showConfirmDialog(
confirmDialog(
context,
showCancelButton: true,
dialogTitle: t.account.reopen,
Expand Down Expand Up @@ -141,12 +141,13 @@ abstract class AccountDetailsActions {
}) {
final scaffold = ScaffoldMessenger.of(context);

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

Expand Down
3 changes: 2 additions & 1 deletion lib/app/budgets/budget_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ class _BudgetDetailsPageState extends State<BudgetDetailsPage> {
icon: Icons.delete,
role: ListTileActionRole.delete,
onClick: () {
showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.budgets.delete,
contentParagraphs: [Text(t.budgets.delete_warning)],
confirmationText: t.general.confirm,
icon: Icons.delete,
).then((confirmed) {
if (confirmed != true) return;

Expand Down
6 changes: 3 additions & 3 deletions lib/app/categories/form/category_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
value: 'merge',
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.merge_type),
leading: const Icon(Icons.merge_type_rounded),
minLeadingWidth: 26,
title: Text(t.categories.merge),
)),
Expand Down Expand Up @@ -349,8 +349,8 @@ class _CategoryFormPageState extends State<CategoryFormPage> {
value: 'merge',
child: ListTile(
contentPadding: EdgeInsets.zero,
leading:
const Icon(Icons.merge_type),
leading: const Icon(
Icons.merge_type_rounded),
minLeadingWidth: 26,
title: Text(t.categories.merge),
)),
Expand Down
8 changes: 5 additions & 3 deletions lib/app/categories/form/category_form_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class CategoryFormFunctions {
static deleteCategory(BuildContext context, String categoryId) {
final t = Translations.of(context);

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.categories.delete_warning_header,
icon: Icons.delete,
contentParagraphs: [
StreamBuilder(
stream: TransactionService.instance
Expand Down Expand Up @@ -68,9 +69,10 @@ class CategoryFormFunctions {

final selCategory = value.first;

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.categories.merge,
icon: Icons.merge_type_rounded,
contentParagraphs: [
StreamBuilder(
stream: TransactionService.instance
Expand Down Expand Up @@ -149,7 +151,7 @@ class CategoryFormFunctions {

final selCategory = value.first;

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.categories.make_child,
contentParagraphs: [
Expand Down
2 changes: 1 addition & 1 deletion lib/app/currencies/currency_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class _CurrencyManagerPageState extends State<CurrencyManagerPage> {
changePreferredCurrency(Currency newCurrency) {
final t = Translations.of(context);

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.currencies.change_preferred_currency_title,
contentParagraphs: [Text(t.currencies.change_preferred_currency_msg)],
Expand Down
2 changes: 1 addition & 1 deletion lib/app/home/widgets/new_transaction_fl_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NewTransactionButton extends StatelessWidget {
_showShouldCreateAccountWarn(BuildContext context) {
final t = Translations.of(context);

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.home.should_create_account_header,
contentParagraphs: [Text(t.home.should_create_account_message)],
Expand Down
2 changes: 1 addition & 1 deletion lib/app/transactions/transaction_details.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class _TransactionDetailsPageState extends State<TransactionDetailsPage> {
showSkipTransactionModal(BuildContext context, MoneyTransaction transaction) {
final nextPaymentDate = transaction.followingDateToNext;

showConfirmDialog(
confirmDialog(
context,
dialogTitle: t.transaction.next_payments.skip_dialog_title,
confirmationText: t.general.confirm,
Expand Down
54 changes: 32 additions & 22 deletions lib/core/presentation/widgets/confirm_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
import 'package:flutter/material.dart';
import 'package:monekin/i18n/translations.g.dart';

/// Display a dialog with a title, a description and confirm/cancel buttons
Future<bool?> showConfirmDialog(
/// Display a dialog with a title, a description and confirm/cancel buttons.
///
/// When the confirm dialogs is closed, it will return `true` or `false` when one of the actions
/// button is pressed, and null if closed without tapping on any icon
Future<bool?> confirmDialog(
BuildContext context, {
required String dialogTitle,
required List<Widget> contentParagraphs,
bool showCancelButton = false,
String? confirmationText,
IconData? icon,
bool canPop = true,
}) {
final t = Translations.of(context);

return showDialog<bool>(
context: context,
builder: (context) => AlertDialog.adaptive(
title: Text(dialogTitle),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: contentParagraphs
.expand((element) => [element, const SizedBox(height: 6)])
.toList(),
barrierDismissible: canPop,
builder: (context) => PopScope(
canPop: canPop,
child: AlertDialog.adaptive(
title: Text(dialogTitle),
icon: icon != null ? Icon(icon, size: 36) : null,
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: contentParagraphs
.expand((element) => [element, const SizedBox(height: 6)])
.toList(),
),
),
),
actions: [
if (showCancelButton)
actions: [
if (showCancelButton)
TextButton(
child: Text(t.general.cancel),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop(false);
},
),
TextButton(
child: Text(t.general.cancel),
child: Text(confirmationText ?? t.general.understood),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop(false);
Navigator.of(context, rootNavigator: true).pop(true);
},
),
TextButton(
child: Text(confirmationText ?? t.general.understood),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop(true);
},
),
],
],
),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TransactionViewActionService {
if (transaction.recurrentInfo.isNoRecurrent)
ListTileActionItem(
label: t.transaction.duplicate_short,
icon: Icons.control_point_duplicate,
icon: Icons.control_point_duplicate_rounded,
onClick: () => TransactionViewActionService()
.cloneTransactionWithAlertAndSnackBar(context,
transaction: transaction),
Expand Down Expand Up @@ -65,8 +65,9 @@ class TransactionViewActionService {
final t = Translations.of(context);
final scaffold = ScaffoldMessenger.of(context);

showConfirmDialog(
confirmDialog(
context,
icon: Icons.delete,
dialogTitle: !isRecurrent
? t.transaction.delete
: t.recurrent_transactions.details.delete_header,
Expand Down Expand Up @@ -108,8 +109,9 @@ class TransactionViewActionService {
final t = Translations.of(context);
final scaffold = ScaffoldMessenger.of(context);

showConfirmDialog(
confirmDialog(
context,
icon: Icons.control_point_duplicate_rounded,
dialogTitle: t.transaction.duplicate,
contentParagraphs: [Text(t.transaction.duplicate_warning_message)],
confirmationText: t.general.continue_text,
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
"swift": "SWIFT"
},
"DELETE": {
"warning-header": "Are you sure?",
"warning-header": "Delete account?",
"warning-text": "This action will delete this account and all its transactions",
"success": "Account deleted successfully"
},
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/strings_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@
"swift": "SWIFT"
},
"DELETE": {
"warning-header": "¿Estas seguro?",
"warning-text": "Esta acción borrara esta cuenta y todas sus transacciones",
"warning-header": "¿Eliminar cuenta?",
"warning-text": "Esta acción borrara esta cuenta y todas sus transacciones. No podrás volver a recuperar esta información tras el borrado.",
"success": "Cuenta eliminada correctamente"
},
"CLOSE": {
Expand Down
14 changes: 7 additions & 7 deletions lib/i18n/translations.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// Locales: 2
/// Strings: 1018 (509 per locale)
///
/// Built on 2024-01-17 at 07:50 UTC
/// Built on 2024-01-24 at 16:04 UTC
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down Expand Up @@ -906,7 +906,7 @@ class _TranslationsAccountDeleteEn {
final _TranslationsEn _root; // ignore: unused_field

// Translations
String get warning_header => 'Are you sure?';
String get warning_header => 'Delete account?';
String get warning_text => 'This action will delete this account and all its transactions';
String get success => 'Account deleted successfully';
}
Expand Down Expand Up @@ -2125,8 +2125,8 @@ class _TranslationsAccountDeleteEs implements _TranslationsAccountDeleteEn {
@override final _TranslationsEs _root; // ignore: unused_field

// Translations
@override String get warning_header => '¿Estas seguro?';
@override String get warning_text => 'Esta acción borrara esta cuenta y todas sus transacciones';
@override String get warning_header => '¿Eliminar cuenta?';
@override String get warning_text => 'Esta acción borrara esta cuenta y todas sus transacciones. No podrás volver a recuperar esta información tras el borrado.';
@override String get success => 'Cuenta eliminada correctamente';
}

Expand Down Expand Up @@ -2940,7 +2940,7 @@ extension on _TranslationsEn {
case 'account.form.tr_before_opening_date': return 'There are transactions in this account with a date before the opening date';
case 'account.form.iban': return 'IBAN';
case 'account.form.swift': return 'SWIFT';
case 'account.delete.warning_header': return 'Are you sure?';
case 'account.delete.warning_header': return 'Delete account?';
case 'account.delete.warning_text': return 'This action will delete this account and all its transactions';
case 'account.delete.success': return 'Account deleted successfully';
case 'account.close.title': return 'Close account';
Expand Down Expand Up @@ -3527,8 +3527,8 @@ extension on _TranslationsEs {
case 'account.form.already_exists': return 'Ya existe otra cuenta con el mismo nombre. Por favor, escriba otro';
case 'account.form.iban': return 'IBAN';
case 'account.form.swift': return 'SWIFT';
case 'account.delete.warning_header': return '¿Estas seguro?';
case 'account.delete.warning_text': return 'Esta acción borrara esta cuenta y todas sus transacciones';
case 'account.delete.warning_header': return '¿Eliminar cuenta?';
case 'account.delete.warning_text': return 'Esta acción borrara esta cuenta y todas sus transacciones. No podrás volver a recuperar esta información tras el borrado.';
case 'account.delete.success': return 'Cuenta eliminada correctamente';
case 'account.close.title': return 'Cerrar cuenta';
case 'account.close.title_short': return 'Cerrar';
Expand Down