@@ -18,7 +18,17 @@ const TextStyle _kToolbarButtonFontStyle = TextStyle(
18
18
19
19
// Colors extracted from https://developer.apple.com/design/resources/.
20
20
// TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/41507.
21
- const Color _kToolbarBackgroundColor = Color (0xEB202020 );
21
+ const CupertinoDynamicColor _kToolbarBackgroundColor = CupertinoDynamicColor .withBrightness (
22
+ // This value was extracted from a screenshot of iOS 16.0.3, as light mode
23
+ // didn't appear in the Apple design resources assets linked above.
24
+ color: Color (0xEBF7F7F7 ),
25
+ darkColor: Color (0xEB202020 ),
26
+ );
27
+
28
+ const CupertinoDynamicColor _kToolbarTextColor = CupertinoDynamicColor .withBrightness (
29
+ color: CupertinoColors .black,
30
+ darkColor: CupertinoColors .white,
31
+ );
22
32
23
33
// Eyeballed value.
24
34
const EdgeInsets _kToolbarButtonPadding = EdgeInsets .symmetric (vertical: 16.0 , horizontal: 18.0 );
@@ -33,22 +43,17 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
33
43
this .onPressed,
34
44
required Widget this .child,
35
45
}) : assert (child != null ),
46
+ text = null ,
36
47
buttonItem = null ;
37
48
38
49
/// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is
39
50
/// a [Text] widget styled like the default iOS text selection toolbar button.
40
- CupertinoTextSelectionToolbarButton .text ({
51
+ const CupertinoTextSelectionToolbarButton .text ({
41
52
super .key,
42
53
this .onPressed,
43
- required String text,
54
+ required this . text,
44
55
}) : buttonItem = null ,
45
- child = Text (
46
- text,
47
- overflow: TextOverflow .ellipsis,
48
- style: _kToolbarButtonFontStyle.copyWith (
49
- color: onPressed != null ? CupertinoColors .white : CupertinoColors .inactiveGray,
50
- ),
51
- );
56
+ child = null ;
52
57
53
58
/// Create an instance of [CupertinoTextSelectionToolbarButton] from the given
54
59
/// [ContextMenuButtonItem] .
@@ -59,6 +64,7 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
59
64
required ContextMenuButtonItem this .buttonItem,
60
65
}) : assert (buttonItem != null ),
61
66
child = null ,
67
+ text = null ,
62
68
onPressed = buttonItem.onPressed;
63
69
64
70
/// {@template flutter.cupertino.CupertinoTextSelectionToolbarButton.child}
@@ -79,6 +85,10 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
79
85
/// {@endtemplate}
80
86
final ContextMenuButtonItem ? buttonItem;
81
87
88
+ /// The text used in the button's label when using
89
+ /// [CupertinoTextSelectionToolbarButton.text] .
90
+ final String ? text;
91
+
82
92
/// Returns the default button label String for the button of the given
83
93
/// [ContextMenuButtonItem] 's [ContextMenuButtonType] .
84
94
static String getButtonLabel (BuildContext context, ContextMenuButtonItem buttonItem) {
@@ -106,12 +116,15 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget {
106
116
@override
107
117
Widget build (BuildContext context) {
108
118
final Widget child = this .child ?? Text (
109
- getButtonLabel (context, buttonItem! ),
110
- overflow: TextOverflow .ellipsis,
111
- style: _kToolbarButtonFontStyle.copyWith (
112
- color: onPressed != null ? CupertinoColors .white : CupertinoColors .inactiveGray,
113
- ),
114
- );
119
+ text ?? getButtonLabel (context, buttonItem! ),
120
+ overflow: TextOverflow .ellipsis,
121
+ style: _kToolbarButtonFontStyle.copyWith (
122
+ color: onPressed != null
123
+ ? _kToolbarTextColor.resolveFrom (context)
124
+ : CupertinoColors .inactiveGray,
125
+ ),
126
+ );
127
+
115
128
return CupertinoButton (
116
129
borderRadius: null ,
117
130
color: _kToolbarBackgroundColor,
0 commit comments