1
1
import 'package:flutter/cupertino.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
4
+ import 'package:flutter/foundation.dart' ;
4
5
5
- Widget _dialogActionText (String text) {
6
+ Widget _materialDialogActionText (String text) {
6
7
return Text (
7
8
text,
8
9
@@ -16,29 +17,19 @@ Widget _dialogActionText(String text) {
16
17
);
17
18
}
18
19
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));
41
31
}
32
+ }
42
33
43
34
/// Tracks the status of a dialog, in being still open or already closed.
44
35
///
@@ -72,9 +63,8 @@ DialogStatus showErrorDialog({
72
63
content: message != null ? SingleChildScrollView (child: Text (message)) : null ,
73
64
actions: [
74
65
_adaptiveAction (
75
- context: context,
76
66
onPressed: () => Navigator .pop (context),
77
- child : _dialogActionText ( zulipLocalizations.errorDialogContinue) ),
67
+ text : zulipLocalizations.errorDialogContinue),
78
68
]));
79
69
return DialogStatus (future);
80
70
}
@@ -94,12 +84,10 @@ void showSuggestedActionDialog({
94
84
content: SingleChildScrollView (child: Text (message)),
95
85
actions: [
96
86
_adaptiveAction (
97
- context: context,
98
87
onPressed: () => Navigator .pop (context),
99
- child : _dialogActionText ( zulipLocalizations.dialogCancel) ),
88
+ text : zulipLocalizations.dialogCancel),
100
89
_adaptiveAction (
101
- context: context,
102
90
onPressed: onActionButtonPress,
103
- child : _dialogActionText ( actionButtonText ?? zulipLocalizations.dialogContinue) ),
91
+ text : actionButtonText ?? zulipLocalizations.dialogContinue),
104
92
]));
105
93
}
0 commit comments