showToolbar method

  1. @override
bool showToolbar()
override

Shows the selection toolbar at the location of the current cursor.

Returns false if a toolbar couldn't be shown, such as when the toolbar is already shown, or when no text selection currently exists.

Implementation

@override
bool showToolbar() {
  // Web is using native dom elements to enable clipboard functionality of the
  // toolbar: copy, paste, select, cut. It might also provide additional
  // functionality depending on the browser (such as translate). Due to this
  // we should not show a Flutter toolbar for the editable text elements.
  if (kIsWeb) {
    return false;
  }

  // selectionOverlay is aggressively released when selection is collapsed
  // to remove unnecessary handles. Since a toolbar is requested here,
  // attempt to create the selectionOverlay if it's not already created.
  if (_selectionOverlay == null) {
    _updateOrDisposeSelectionOverlayIfNeeded();
  }

  if (_selectionOverlay == null || _selectionOverlay!.toolbar != null) {
    return false;
  }

  _selectionOverlay!.update(textEditingValue);
  _selectionOverlay!.showToolbar();
  return true;
}