getSelectableButtonItems static method
- {required SelectionGeometry selectionGeometry,
- required VoidCallback onCopy,
- required VoidCallback onSelectAll}
Returns the ContextMenuButtonItem
s representing the buttons in this
platform's default selection menu.
For example, SelectableRegion uses this to generate the default buttons for its context menu.
See also:
- SelectableRegionState.contextMenuButtonItems, which gives the
ContextMenuButtonItem
s for a specific SelectableRegion. - EditableText.getEditableButtonItems, which performs a similar role but for content that is both selectable and editable.
- AdaptiveTextSelectionToolbar, which builds the toolbar itself, and can
take a list of
ContextMenuButtonItem
s with AdaptiveTextSelectionToolbar.buttonItems. - AdaptiveTextSelectionToolbar.getAdaptiveButtons, which builds the button
Widgets for the current platform given
ContextMenuButtonItem
s.
Implementation
static List<ContextMenuButtonItem> getSelectableButtonItems({
required final SelectionGeometry selectionGeometry,
required final VoidCallback onCopy,
required final VoidCallback onSelectAll,
}) {
final bool canCopy = selectionGeometry.status == SelectionStatus.uncollapsed;
final bool canSelectAll = selectionGeometry.hasContent;
// Determine which buttons will appear so that the order and total number is
// known. A button's position in the menu can slightly affect its
// appearance.
return <ContextMenuButtonItem>[
if (canCopy)
ContextMenuButtonItem(
onPressed: onCopy,
type: ContextMenuButtonType.copy,
),
if (canSelectAll)
ContextMenuButtonItem(
onPressed: onSelectAll,
type: ContextMenuButtonType.selectAll,
),
];
}