1
+ import 'package:flutter/cupertino.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
4
+ import 'package:flutter/foundation.dart' ;
3
5
4
- Widget _dialogActionText (String text) {
6
+ Widget _materialDialogActionText (String text) {
5
7
return Text (
6
8
text,
7
9
@@ -15,6 +17,20 @@ Widget _dialogActionText(String text) {
15
17
);
16
18
}
17
19
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));
31
+ }
32
+ }
33
+
18
34
/// Tracks the status of a dialog, in being still open or already closed.
19
35
///
20
36
/// See also:
@@ -42,13 +58,13 @@ DialogStatus showErrorDialog({
42
58
final zulipLocalizations = ZulipLocalizations .of (context);
43
59
final future = showDialog <void >(
44
60
context: context,
45
- builder: (BuildContext context) => AlertDialog (
61
+ builder: (BuildContext context) => AlertDialog . adaptive (
46
62
title: Text (title),
47
63
content: message != null ? SingleChildScrollView (child: Text (message)) : null ,
48
64
actions: [
49
- TextButton (
65
+ _adaptiveAction (
50
66
onPressed: () => Navigator .pop (context),
51
- child : _dialogActionText ( zulipLocalizations.errorDialogContinue) ),
67
+ text : zulipLocalizations.errorDialogContinue),
52
68
]));
53
69
return DialogStatus (future);
54
70
}
@@ -63,15 +79,15 @@ void showSuggestedActionDialog({
63
79
final zulipLocalizations = ZulipLocalizations .of (context);
64
80
showDialog <void >(
65
81
context: context,
66
- builder: (BuildContext context) => AlertDialog (
82
+ builder: (BuildContext context) => AlertDialog . adaptive (
67
83
title: Text (title),
68
84
content: SingleChildScrollView (child: Text (message)),
69
85
actions: [
70
- TextButton (
86
+ _adaptiveAction (
71
87
onPressed: () => Navigator .pop (context),
72
- child : _dialogActionText ( zulipLocalizations.dialogCancel) ),
73
- TextButton (
88
+ text : zulipLocalizations.dialogCancel),
89
+ _adaptiveAction (
74
90
onPressed: onActionButtonPress,
75
- child : _dialogActionText ( actionButtonText ?? zulipLocalizations.dialogContinue) ),
91
+ text : actionButtonText ?? zulipLocalizations.dialogContinue),
76
92
]));
77
93
}
0 commit comments