From a45e846321e727cd1c0eb4a28ac2514ad1922fdc Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Thu, 7 Mar 2024 15:17:43 +0100 Subject: [PATCH] feat: Feedback on reset / restore DB, simplify Dialogs --- .../lib/l10n/app_de.arb | 1 + .../lib/l10n/app_en.arb | 1 + .../lib/view/screens/edit/lineup_edit.dart | 8 +-- .../view/screens/more/settings/settings.dart | 32 ++++++----- .../lib/view/widgets/dialogs.dart | 56 +++++++++++++------ 5 files changed, 63 insertions(+), 35 deletions(-) diff --git a/wrestling_scoreboard_client/lib/l10n/app_de.arb b/wrestling_scoreboard_client/lib/l10n/app_de.arb index c1d23453..b2ec47bd 100644 --- a/wrestling_scoreboard_client/lib/l10n/app_de.arb +++ b/wrestling_scoreboard_client/lib/l10n/app_de.arb @@ -56,6 +56,7 @@ "noItems": "Keine Einträge vorhanden.", "optional": "Optional", "mandatoryField": "Das ist ein Pflichtfeld.", + "actionSuccessful": "Die Aktion war erfolgreich.", "noWebSocketConnection": "Die Verbindung zum Server konnte nicht aufgebaut werden oder wurde unterbrochen.", "notFoundException": "Element wurde nicht gefunden :/", "invalidParameterException": "Die Änderung war nicht erfolgreich, bitte überprüfe deine Eingabeparameter.", diff --git a/wrestling_scoreboard_client/lib/l10n/app_en.arb b/wrestling_scoreboard_client/lib/l10n/app_en.arb index 2b28905f..30b61f22 100644 --- a/wrestling_scoreboard_client/lib/l10n/app_en.arb +++ b/wrestling_scoreboard_client/lib/l10n/app_en.arb @@ -59,6 +59,7 @@ "noItems": "No items available.", "optional": "Optional", "mandatoryField": "This is a mandatory field.", + "actionSuccessful": "The action was successful.", "noWebSocketConnection": "The connection to the server could not be established or was interrupted.", "notFoundException": "Element was not found :/", "invalidParameterException": "The change was not successful, please check your input parameters.", diff --git a/wrestling_scoreboard_client/lib/view/screens/edit/lineup_edit.dart b/wrestling_scoreboard_client/lib/view/screens/edit/lineup_edit.dart index 723c468f..0680c0bb 100644 --- a/wrestling_scoreboard_client/lib/view/screens/edit/lineup_edit.dart +++ b/wrestling_scoreboard_client/lib/view/screens/edit/lineup_edit.dart @@ -87,12 +87,10 @@ class LineupEditState extends ConsumerState { icon: const Icon(Icons.autorenew), label: Text(localizations.saveAndGenerate), onSubmit: () async { - final hasConfirmed = await showDialog( + final hasConfirmed = await showOkCanelDialog( context: context, - builder: (context) => OkCancelDialog( - getResult: () => true, - child: Text(localizations.warningBoutGenerate), - ), + getResult: () => true, + child: Text(localizations.warningBoutGenerate), ); if (hasConfirmed == true) { await handleSubmit(navigator, onSubmitGenerate: widget.onSubmitGenerate); diff --git a/wrestling_scoreboard_client/lib/view/screens/more/settings/settings.dart b/wrestling_scoreboard_client/lib/view/screens/more/settings/settings.dart index fdcf2e55..55e73b35 100644 --- a/wrestling_scoreboard_client/lib/view/screens/more/settings/settings.dart +++ b/wrestling_scoreboard_client/lib/view/screens/more/settings/settings.dart @@ -159,19 +159,16 @@ class CustomSettingsScreen extends ConsumerWidget { Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(fontFamily.value), IconButton( - onPressed: () => showDialog( - context: context, - builder: (context) => OkDialog( - child: Text( - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz', - style: fontFamily.key != null - ? GoogleFonts.getTextTheme( - fontFamily.key!, currentTextTheme) - .headlineMedium - : null), - ), - ), - icon: const Icon(Icons.visibility)) + onPressed: () => showOkDialog( + context: context, + child: Text('ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz', + style: fontFamily.key != null + ? GoogleFonts.getTextTheme(fontFamily.key!, currentTextTheme) + .headlineMedium + : null), + ), + icon: const Icon(Icons.visibility), + ), ]) ); }, @@ -427,6 +424,9 @@ class CustomSettingsScreen extends ConsumerWidget { onTap: () async { final dataManager = await ref.read(dataManagerNotifierProvider); await dataManager.resetDatabase(); + if (context.mounted) { + await showOkDialog(context: context, child: Text(localizations.actionSuccessful)); + } }, ), ListTile( @@ -435,6 +435,9 @@ class CustomSettingsScreen extends ConsumerWidget { onTap: () async { final dataManager = await ref.read(dataManagerNotifierProvider); await dataManager.restoreDefaultDatabase(); + if (context.mounted) { + await showOkDialog(context: context, child: Text(localizations.actionSuccessful)); + } }, ), ListTile( @@ -449,6 +452,9 @@ class CustomSettingsScreen extends ConsumerWidget { File file = File(filePickerResult.files.single.path!); final dataManager = await ref.read(dataManagerNotifierProvider); await dataManager.restoreDatabase(await file.readAsString(encoding: const Utf8Codec())); + if (context.mounted) { + await showOkDialog(context: context, child: Text(localizations.actionSuccessful)); + } } }, ), diff --git a/wrestling_scoreboard_client/lib/view/widgets/dialogs.dart b/wrestling_scoreboard_client/lib/view/widgets/dialogs.dart index 526e5408..a715ba70 100644 --- a/wrestling_scoreboard_client/lib/view/widgets/dialogs.dart +++ b/wrestling_scoreboard_client/lib/view/widgets/dialogs.dart @@ -28,6 +28,15 @@ class OkDialog extends StatelessWidget { } } +Future showOkDialog({required BuildContext context, required Widget child}) async { + await showDialog( + context: context, + builder: (context) => OkDialog( + child: child, + ), + ); +} + class OkCancelDialog extends StatelessWidget { final Widget child; final T Function() getResult; @@ -57,21 +66,33 @@ class OkCancelDialog extends StatelessWidget { } } +Future showOkCanelDialog({ + required BuildContext context, + required Widget child, + required T Function() getResult, +}) async { + return await showDialog( + context: context, + builder: (context) => OkCancelDialog( + getResult: getResult, + child: child, + ), + ); +} + Future showExceptionDialog({required BuildContext context, required Exception exception}) async { final localizations = AppLocalizations.of(context)!; - await showDialog( + await showOkDialog( context: context, - builder: (context) => OkDialog( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - if (exception is RestException) SelectableText(localizations.invalidParameterException), - SelectableText( - exception.toString(), - style: TextStyle(color: Theme.of(context).disabledColor, fontSize: 10), - ), - ], - ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + if (exception is RestException) SelectableText(localizations.invalidParameterException), + SelectableText( + exception.toString(), + style: TextStyle(color: Theme.of(context).disabledColor, fontSize: 10), + ), + ], ), ); } @@ -85,11 +106,12 @@ class TextInputDialog extends StatelessWidget { Widget build(BuildContext context) { String? result; return OkCancelDialog( - child: TextFormField( - initialValue: initialValue, - onChanged: (value) => result = value, - ), - getResult: () => result); + child: TextFormField( + initialValue: initialValue, + onChanged: (value) => result = value, + ), + getResult: () => result, + ); } }