11import 'package:flutter/cupertino.dart' ;
22import 'package:flutter/material.dart' ;
33import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
4+ import 'package:flutter/foundation.dart' ;
45
5- Widget _dialogActionText (String text) {
6+ Widget _materialDialogActionText (String text) {
67 return Text (
78 text,
89
@@ -16,29 +17,19 @@ Widget _dialogActionText(String text) {
1617 );
1718}
1819
19- /// Sets the dialog action to be platform appropriate
20- /// by displaying a [CupertinoDialogAction] for IOS platforms
21- /// and a regular [TextButton] otherwise.
22- Widget _adaptiveAction (
23- {required BuildContext context,
24- required VoidCallback onPressed,
25- required Widget child}) {
26- final ThemeData theme = Theme .of (context);
27- switch (theme.platform) {
28- case TargetPlatform .android:
29- return TextButton (onPressed: onPressed, child: child);
30- case TargetPlatform .fuchsia:
31- return TextButton (onPressed: onPressed, child: child);
32- case TargetPlatform .linux:
33- return TextButton (onPressed: onPressed, child: child);
34- case TargetPlatform .windows:
35- return TextButton (onPressed: onPressed, child: child);
36- case TargetPlatform .iOS:
37- return CupertinoDialogAction (onPressed: onPressed, child: child);
38- case TargetPlatform .macOS:
39- return CupertinoDialogAction (onPressed: onPressed, child: child);
40- }
20+ /// A platform-appropriate action for [AlertDialog.adaptive] 's [actions] param.
21+ Widget _adaptiveAction ({required VoidCallback onPressed, required String text}) {
22+ switch (defaultTargetPlatform) {
23+ case TargetPlatform .android:
24+ case TargetPlatform .fuchsia:
25+ case TargetPlatform .linux:
26+ case TargetPlatform .windows:
27+ return TextButton (onPressed: onPressed, child: _materialDialogActionText (text));
28+ case TargetPlatform .iOS:
29+ case TargetPlatform .macOS:
30+ return CupertinoDialogAction (onPressed: onPressed, child: Text (text));
4131 }
32+ }
4233
4334/// Tracks the status of a dialog, in being still open or already closed.
4435///
@@ -72,9 +63,8 @@ DialogStatus showErrorDialog({
7263 content: message != null ? SingleChildScrollView (child: Text (message)) : null ,
7364 actions: [
7465 _adaptiveAction (
75- context: context,
7666 onPressed: () => Navigator .pop (context),
77- child : _dialogActionText ( zulipLocalizations.errorDialogContinue) ),
67+ text : zulipLocalizations.errorDialogContinue),
7868 ]));
7969 return DialogStatus (future);
8070}
@@ -94,12 +84,10 @@ void showSuggestedActionDialog({
9484 content: SingleChildScrollView (child: Text (message)),
9585 actions: [
9686 _adaptiveAction (
97- context: context,
9887 onPressed: () => Navigator .pop (context),
99- child : _dialogActionText ( zulipLocalizations.dialogCancel) ),
88+ text : zulipLocalizations.dialogCancel),
10089 _adaptiveAction (
101- context: context,
10290 onPressed: onActionButtonPress,
103- child : _dialogActionText ( actionButtonText ?? zulipLocalizations.dialogContinue) ),
91+ text : actionButtonText ?? zulipLocalizations.dialogContinue),
10492 ]));
10593}
0 commit comments