@@ -1893,7 +1893,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
1893
1893
final GlobalKey _editableKey = GlobalKey ();
1894
1894
1895
1895
/// Detects whether the clipboard can paste.
1896
- final ClipboardStatusNotifier ? clipboardStatus = kIsWeb ? null : ClipboardStatusNotifier ();
1896
+ final ClipboardStatusNotifier clipboardStatus = ClipboardStatusNotifier ();
1897
1897
1898
1898
TextInputConnection ? _textInputConnection;
1899
1899
bool get _hasInputConnection => _textInputConnection? .attached ?? false ;
@@ -1996,8 +1996,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
1996
1996
return widget.toolbarOptions.paste && ! widget.readOnly;
1997
1997
}
1998
1998
return ! widget.readOnly
1999
- && (clipboardStatus == null
2000
- || clipboardStatus! .value == ClipboardStatus .pasteable);
1999
+ && (clipboardStatus.value == ClipboardStatus .pasteable);
2001
2000
}
2002
2001
2003
2002
@override
@@ -2074,7 +2073,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2074
2073
break ;
2075
2074
}
2076
2075
}
2077
- clipboardStatus? .update ();
2076
+ clipboardStatus.update ();
2078
2077
}
2079
2078
2080
2079
/// Cut current selection to [Clipboard] .
@@ -2099,7 +2098,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2099
2098
});
2100
2099
hideToolbar ();
2101
2100
}
2102
- clipboardStatus? .update ();
2101
+ clipboardStatus.update ();
2103
2102
}
2104
2103
2105
2104
/// Paste text from [Clipboard] .
@@ -2285,7 +2284,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2285
2284
},
2286
2285
type: ContextMenuButtonType .copy,
2287
2286
),
2288
- if (toolbarOptions.paste && clipboardStatus != null && pasteEnabled)
2287
+ if (toolbarOptions.paste && pasteEnabled)
2289
2288
ContextMenuButtonItem (
2290
2289
onPressed: () {
2291
2290
pasteText (SelectionChangedCause .toolbar);
@@ -2386,7 +2385,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2386
2385
/// button Widgets for the current platform given [ContextMenuButtonItem] s.
2387
2386
List <ContextMenuButtonItem > get contextMenuButtonItems {
2388
2387
return buttonItemsForToolbarOptions () ?? EditableText .getEditableButtonItems (
2389
- clipboardStatus: clipboardStatus? .value,
2388
+ clipboardStatus: clipboardStatus.value,
2390
2389
onCopy: copyEnabled
2391
2390
? () => copySelection (SelectionChangedCause .toolbar)
2392
2391
: null ,
@@ -2407,7 +2406,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2407
2406
@override
2408
2407
void initState () {
2409
2408
super .initState ();
2410
- clipboardStatus? .addListener (_onChangedClipboardStatus);
2409
+ clipboardStatus.addListener (_onChangedClipboardStatus);
2411
2410
widget.controller.addListener (_didChangeTextEditingValue);
2412
2411
widget.focusNode.addListener (_handleFocusChanged);
2413
2412
_scrollController.addListener (_onEditableScroll);
@@ -2531,8 +2530,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2531
2530
final bool canPaste = widget.selectionControls is TextSelectionHandleControls
2532
2531
? pasteEnabled
2533
2532
: widget.selectionControls? .canPaste (this ) ?? false ;
2534
- if (widget.selectionEnabled && pasteEnabled && clipboardStatus != null && canPaste) {
2535
- clipboardStatus! .update ();
2533
+ if (widget.selectionEnabled && pasteEnabled && canPaste) {
2534
+ clipboardStatus.update ();
2536
2535
}
2537
2536
}
2538
2537
@@ -2553,8 +2552,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2553
2552
_selectionOverlay = null ;
2554
2553
widget.focusNode.removeListener (_handleFocusChanged);
2555
2554
WidgetsBinding .instance.removeObserver (this );
2556
- clipboardStatus? .removeListener (_onChangedClipboardStatus);
2557
- clipboardStatus? .dispose ();
2555
+ clipboardStatus.removeListener (_onChangedClipboardStatus);
2556
+ clipboardStatus.dispose ();
2558
2557
_cursorVisibilityNotifier.dispose ();
2559
2558
super .dispose ();
2560
2559
assert (_batchEditDepth <= 0 , 'unfinished batch edits: $_batchEditDepth ' );
@@ -3688,17 +3687,18 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
3688
3687
@override
3689
3688
bool showToolbar () {
3690
3689
// Web is using native dom elements to enable clipboard functionality of the
3691
- // toolbar: copy, paste, select, cut. It might also provide additional
3692
- // functionality depending on the browser (such as translate). Due to this
3693
- // we should not show a Flutter toolbar for the editable text elements.
3694
- if (kIsWeb) {
3690
+ // context menu: copy, paste, select, cut. It might also provide additional
3691
+ // functionality depending on the browser (such as translate). Due to this,
3692
+ // we should not show a Flutter toolbar for the editable text elements
3693
+ // unless the browser's context menu is explicitly disabled.
3694
+ if (kIsWeb && BrowserContextMenu .enabled) {
3695
3695
return false ;
3696
3696
}
3697
3697
3698
3698
if (_selectionOverlay == null ) {
3699
3699
return false ;
3700
3700
}
3701
- clipboardStatus? .update ();
3701
+ clipboardStatus.update ();
3702
3702
_selectionOverlay! .showToolbar ();
3703
3703
return true ;
3704
3704
}
@@ -3912,7 +3912,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
3912
3912
&& (widget.selectionControls is TextSelectionHandleControls
3913
3913
? pasteEnabled
3914
3914
: pasteEnabled && (widget.selectionControls? .canPaste (this ) ?? false ))
3915
- && (clipboardStatus == null || clipboardStatus ! .value == ClipboardStatus .pasteable)
3915
+ && (clipboardStatus.value == ClipboardStatus .pasteable)
3916
3916
? () {
3917
3917
controls? .handlePaste (this );
3918
3918
pasteText (SelectionChangedCause .toolbar);
0 commit comments