Show correct cancel text in ResponsiveDialog

This commit is contained in:
Elias Bonnici 2024-04-10 13:29:39 +02:00
parent e21fb7525c
commit fab5fa2687
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF

View File

@ -51,12 +51,19 @@ class _ResponsiveDialogState extends State<ResponsiveDialog> {
_focus.dispose(); _focus.dispose();
} }
String _getCancelText(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return widget.onCancel == null && widget.actions.isEmpty
? l10n.s_close
: l10n.s_cancel;
}
Widget _buildFullscreen(BuildContext context) => Scaffold( Widget _buildFullscreen(BuildContext context) => Scaffold(
appBar: AppBar( appBar: AppBar(
title: widget.title, title: widget.title,
actions: widget.actions, actions: widget.actions,
leading: IconButton( leading: IconButton(
tooltip: AppLocalizations.of(context)!.s_close, tooltip: _getCancelText(context),
icon: const Icon(Symbols.close), icon: const Icon(Symbols.close),
onPressed: widget.allowCancel onPressed: widget.allowCancel
? () { ? () {
@ -72,10 +79,6 @@ class _ResponsiveDialogState extends State<ResponsiveDialog> {
); );
Widget _buildDialog(BuildContext context) { Widget _buildDialog(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final cancelText = widget.onCancel == null && widget.actions.isEmpty
? l10n.s_close
: l10n.s_cancel;
return PopScope( return PopScope(
canPop: widget.allowCancel, canPop: widget.allowCancel,
child: AlertDialog( child: AlertDialog(
@ -94,7 +97,7 @@ class _ResponsiveDialogState extends State<ResponsiveDialog> {
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
: null, : null,
child: Text(cancelText), child: Text(_getCancelText(context)),
), ),
...widget.actions ...widget.actions
], ],