contextMenuBuilder property

Widget Function(BuildContext context, SmoothSelectionRegionState selectableRegionState)? contextMenuBuilder
final

Custom context menu builder for text selection.

When selectable is true, this builder replaces the default SelectionArea.contextMenuBuilder. Receives the current BuildContext and the SmoothSelectionRegionState, which provides contextMenuAnchors, contextMenuButtonItems, dispatchEvent, registrar, and other methods to control text selection.

If null (default), the built-in adaptive toolbar with clipboard filter is used.

Example:

SmoothMarkdown(
  data: markdownText,
  selectable: true,
  contextMenuBuilder: (context, state) {
    return AdaptiveTextSelectionToolbar.buttonItems(
      anchors: state.contextMenuAnchors,
      buttonItems: [
        ...state.contextMenuButtonItems,
        ContextMenuButtonItem(
          label: '自定义操作',
          onPressed: () {
            // Custom action
          },
        ),
      ],
    );
  },
)

Defaults to null.

Implementation

final Widget Function(BuildContext context,
    SmoothSelectionRegionState selectableRegionState)? contextMenuBuilder;