@@ -11,9 +11,6 @@ import 'package:flutter/scheduler.dart';
11
11
import 'package:flutter/services.dart' ;
12
12
import 'package:flutter/widgets.dart' ;
13
13
14
- import 'button_theme.dart' ;
15
- import 'colors.dart' ;
16
- import 'constants.dart' ;
17
14
import 'debug.dart' ;
18
15
import 'flat_button.dart' ;
19
16
import 'icon_button.dart' ;
@@ -57,18 +54,6 @@ class _TextSelectionToolbar extends StatefulWidget {
57
54
_TextSelectionToolbarState createState () => _TextSelectionToolbarState ();
58
55
}
59
56
60
- // Intermediate data used for building menu items with the _getItems method.
61
- class _ItemData {
62
- const _ItemData (
63
- this .onPressed,
64
- this .label,
65
- ) : assert (onPressed != null ),
66
- assert (label != null );
67
-
68
- final VoidCallback onPressed;
69
- final String label;
70
- }
71
-
72
57
class _TextSelectionToolbarState extends State <_TextSelectionToolbar > with TickerProviderStateMixin {
73
58
ClipboardStatusNotifier _clipboardStatus;
74
59
@@ -80,25 +65,11 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke
80
65
// The key for _TextSelectionToolbarContainer.
81
66
UniqueKey _containerKey = UniqueKey ();
82
67
83
- Widget _getItem (_ItemData itemData, bool isFirst, bool isLast) {
84
- assert (isFirst != null );
85
- assert (isLast != null );
86
- return ButtonTheme .fromButtonThemeData (
87
- data: ButtonTheme .of (context).copyWith (
88
- height: kMinInteractiveDimension,
89
- minWidth: kMinInteractiveDimension,
90
- ),
91
- child: FlatButton (
92
- onPressed: itemData.onPressed,
93
- padding: EdgeInsets .only (
94
- // These values were eyeballed to match the native text selection menu
95
- // on a Pixel 2 running Android 10.
96
- left: 9.5 + (isFirst ? 5.0 : 0.0 ),
97
- right: 9.5 + (isLast ? 5.0 : 0.0 ),
98
- ),
99
- shape: Border .all (width: 0.0 , color: Colors .transparent),
100
- child: Text (itemData.label),
101
- ),
68
+ FlatButton _getItem (VoidCallback onPressed, String label) {
69
+ assert (onPressed != null );
70
+ return FlatButton (
71
+ child: Text (label),
72
+ onPressed: onPressed,
102
73
);
103
74
}
104
75
@@ -182,20 +153,20 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke
182
153
}
183
154
184
155
final MaterialLocalizations localizations = MaterialLocalizations .of (context);
185
- final List <_ItemData > itemDatas = < _ItemData > [
156
+ final List <Widget > items = < Widget > [
186
157
if (widget.handleCut != null )
187
- _ItemData (widget.handleCut, localizations.cutButtonLabel),
158
+ _getItem (widget.handleCut, localizations.cutButtonLabel),
188
159
if (widget.handleCopy != null )
189
- _ItemData (widget.handleCopy, localizations.copyButtonLabel),
160
+ _getItem (widget.handleCopy, localizations.copyButtonLabel),
190
161
if (widget.handlePaste != null
191
162
&& _clipboardStatus.value == ClipboardStatus .pasteable)
192
- _ItemData (widget.handlePaste, localizations.pasteButtonLabel),
163
+ _getItem (widget.handlePaste, localizations.pasteButtonLabel),
193
164
if (widget.handleSelectAll != null )
194
- _ItemData (widget.handleSelectAll, localizations.selectAllButtonLabel),
165
+ _getItem (widget.handleSelectAll, localizations.selectAllButtonLabel),
195
166
];
196
167
197
168
// If there is no option available, build an empty widget.
198
- if (itemDatas .isEmpty) {
169
+ if (items .isEmpty) {
199
170
return const SizedBox (width: 0.0 , height: 0.0 );
200
171
}
201
172
@@ -208,20 +179,14 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke
208
179
// API 28.
209
180
duration: const Duration (milliseconds: 140 ),
210
181
child: Material (
211
- // This value was eyeballed to match the native text selection menu on
212
- // a Pixel 2 running Android 10.
213
- borderRadius: const BorderRadius .all (Radius .circular (7.0 )),
214
- clipBehavior: Clip .antiAlias,
215
182
elevation: 1.0 ,
216
- type: MaterialType .card,
217
183
child: _TextSelectionToolbarItems (
218
184
isAbove: widget.isAbove,
219
185
overflowOpen: _overflowOpen,
220
186
children: < Widget > [
221
187
// The navButton that shows and hides the overflow menu is the
222
188
// first child.
223
189
Material (
224
- type: MaterialType .card,
225
190
child: IconButton (
226
191
// TODO(justinmc): This should be an AnimatedIcon, but
227
192
// AnimatedIcons doesn't yet support arrow_back to more_vert.
@@ -237,8 +202,7 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke
237
202
: localizations.moreButtonTooltip,
238
203
),
239
204
),
240
- for (int i = 0 ; i < itemDatas.length; i++ )
241
- _getItem (itemDatas[i], i == 0 , i == itemDatas.length - 1 )
205
+ ...items,
242
206
],
243
207
),
244
208
),
0 commit comments