contextMenuBuilder property

SelectableRegionContextMenuBuilder? contextMenuBuilder
final

Builds the text selection toolbar when requested by the user.

The context menu is built when EditableTextState.showToolbar is called, typically by one of the callbacks installed by the widget created by TextSelectionGestureDetectorBuilder.buildGestureDetector. The widget returned by contextMenuBuilder is passed to a ContextMenuController.

If no callback is provided, no context menu will be shown.

The EditableTextContextMenuBuilder signature used by the contextMenuBuilder callback has two parameters, the BuildContext of the EditableText and the EditableTextState of the EditableText.

The EditableTextState has two properties that are especially useful when building the widgets for the context menu:

The TextSelectionToolbarLayoutDelegate class may be particularly useful in honoring the preferred anchor positions.

For backwards compatibility, when selectionControls is set to an object that does not mix in TextSelectionHandleControls, contextMenuBuilder is ignored and the TextSelectionControls.buildToolbar method is used instead.

This example shows how to customize the menu, in this case by keeping the default buttons for the platform but modifying their appearance.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.EditableText.contextMenuBuilder.1 mysample

This example shows how to show a custom button only when an email address is currently selected.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.EditableText.contextMenuBuilder.2 mysample

See also:

If not provided, will build a default menu based on the ambient ThemeData.platform.

This example shows how to build a custom context menu for any selected content in a SelectionArea.
link

To create a local project with this code sample, run:
flutter create --sample=material.SelectionArea.contextMenuBuilder.1 mysample

See also:

Implementation

final SelectableRegionContextMenuBuilder? contextMenuBuilder;