@@ -477,6 +477,7 @@ class TextSelectionOverlay {
477477 context: context,
478478 builder: spellCheckSuggestionsToolbarBuilder,
479479 );
480+ hideHandles ();
480481 }
481482
482483 /// {@macro flutter.widgets.SelectionOverlay.showMagnifier}
@@ -568,15 +569,25 @@ class TextSelectionOverlay {
568569 bool get handlesAreVisible => _selectionOverlay._handles != null && handlesVisible;
569570
570571 /// Whether the toolbar is currently visible.
571- bool get toolbarIsVisible {
572- return selectionControls is TextSelectionHandleControls
573- ? _selectionOverlay._contextMenuControllerIsShown
574- : _selectionOverlay._toolbar != null ;
575- }
572+ ///
573+ /// Includes both the text selection toolbar and the spell check menu.
574+ ///
575+ /// See also:
576+ ///
577+ /// * [spellCheckToolbarIsVisible] , which is only whether the spell check menu
578+ /// specifically is visible.
579+ bool get toolbarIsVisible => _selectionOverlay._toolbarIsVisible;
576580
577581 /// Whether the magnifier is currently visible.
578582 bool get magnifierIsVisible => _selectionOverlay._magnifierController.shown;
579583
584+ /// Whether the spell check menu is currently visible.
585+ ///
586+ /// See also:
587+ ///
588+ /// * [toolbarIsVisible] , which is whether any toolbar is visible.
589+ bool get spellCheckToolbarIsVisible => _selectionOverlay._spellCheckToolbarController.isShown;
590+
580591 /// {@macro flutter.widgets.SelectionOverlay.hide}
581592 void hide () => _selectionOverlay.hide ();
582593
@@ -979,6 +990,12 @@ class SelectionOverlay {
979990 /// {@macro flutter.widgets.magnifier.TextMagnifierConfiguration.details}
980991 final TextMagnifierConfiguration magnifierConfiguration;
981992
993+ bool get _toolbarIsVisible {
994+ return selectionControls is TextSelectionHandleControls
995+ ? _contextMenuController.isShown || _spellCheckToolbarController.isShown
996+ : _toolbar != null || _spellCheckToolbarController.isShown;
997+ }
998+
982999 /// {@template flutter.widgets.SelectionOverlay.showMagnifier}
9831000 /// Shows the magnifier, and hides the toolbar if it was showing when [showMagnifier]
9841001 /// was called. This is safe to call on platforms not mobile, since
@@ -990,7 +1007,7 @@ class SelectionOverlay {
9901007 /// [MagnifierController.shown] .
9911008 /// {@endtemplate}
9921009 void showMagnifier (MagnifierInfo initialMagnifierInfo) {
993- if (_toolbar != null || _contextMenuControllerIsShown ) {
1010+ if (_toolbarIsVisible ) {
9941011 hideToolbar ();
9951012 }
9961013
@@ -1288,7 +1305,7 @@ class SelectionOverlay {
12881305 // Manages the context menu. Not necessarily visible when non-null.
12891306 final ContextMenuController _contextMenuController = ContextMenuController ();
12901307
1291- bool get _contextMenuControllerIsShown => _contextMenuController.isShown ;
1308+ final ContextMenuController _spellCheckToolbarController = ContextMenuController () ;
12921309
12931310 /// {@template flutter.widgets.SelectionOverlay.showHandles}
12941311 /// Builds the handles by inserting them into the [context] 's overlay.
@@ -1360,7 +1377,7 @@ class SelectionOverlay {
13601377 }
13611378
13621379 final RenderBox renderBox = context.findRenderObject ()! as RenderBox ;
1363- _contextMenuController .show (
1380+ _spellCheckToolbarController .show (
13641381 context: context,
13651382 contextMenuBuilder: (BuildContext context) {
13661383 return _SelectionToolbarWrapper (
@@ -1395,6 +1412,8 @@ class SelectionOverlay {
13951412 _toolbar? .markNeedsBuild ();
13961413 if (_contextMenuController.isShown) {
13971414 _contextMenuController.markNeedsBuild ();
1415+ } else if (_spellCheckToolbarController.isShown) {
1416+ _spellCheckToolbarController.markNeedsBuild ();
13981417 }
13991418 });
14001419 } else {
@@ -1405,6 +1424,8 @@ class SelectionOverlay {
14051424 _toolbar? .markNeedsBuild ();
14061425 if (_contextMenuController.isShown) {
14071426 _contextMenuController.markNeedsBuild ();
1427+ } else if (_spellCheckToolbarController.isShown) {
1428+ _spellCheckToolbarController.markNeedsBuild ();
14081429 }
14091430 }
14101431 }
@@ -1419,7 +1440,7 @@ class SelectionOverlay {
14191440 _handles! [1 ].remove ();
14201441 _handles = null ;
14211442 }
1422- if (_toolbar != null || _contextMenuControllerIsShown ) {
1443+ if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown ) {
14231444 hideToolbar ();
14241445 }
14251446 }
@@ -1431,6 +1452,7 @@ class SelectionOverlay {
14311452 /// {@endtemplate}
14321453 void hideToolbar () {
14331454 _contextMenuController.remove ();
1455+ _spellCheckToolbarController.remove ();
14341456 if (_toolbar == null ) {
14351457 return ;
14361458 }
0 commit comments