Skip to content

Commit

Permalink
feat: Feedback on reset / restore DB, simplify Dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Mar 7, 2024
1 parent fb62a31 commit a45e846
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
1 change: 1 addition & 0 deletions wrestling_scoreboard_client/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions wrestling_scoreboard_client/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ class LineupEditState extends ConsumerState<LineupEdit> {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
])
);
},
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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));
}
}
},
),
Expand Down
56 changes: 39 additions & 17 deletions wrestling_scoreboard_client/lib/view/widgets/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ class OkDialog extends StatelessWidget {
}
}

Future<void> showOkDialog({required BuildContext context, required Widget child}) async {
await showDialog(
context: context,
builder: (context) => OkDialog(
child: child,
),
);
}

class OkCancelDialog<T extends Object?> extends StatelessWidget {
final Widget child;
final T Function() getResult;
Expand Down Expand Up @@ -57,21 +66,33 @@ class OkCancelDialog<T extends Object?> extends StatelessWidget {
}
}

Future<T?> showOkCanelDialog<T>({
required BuildContext context,
required Widget child,
required T Function() getResult,
}) async {
return await showDialog<T>(
context: context,
builder: (context) => OkCancelDialog<T>(
getResult: getResult,
child: child,
),
);
}

Future<void> 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),
),
],
),
);
}
Expand All @@ -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,
);
}
}

Expand Down

0 comments on commit a45e846

Please sign in to comment.