getEditableButtonItems static method
- required ClipboardStatus? clipboardStatus,
- required VoidCallback? onCopy,
- required VoidCallback? onCut,
- required VoidCallback? onPaste,
- required VoidCallback? onSelectAll,
- required VoidCallback? onLookUp,
- required VoidCallback? onSearchWeb,
- required VoidCallback? onLiveTextInput,
Returns the ContextMenuButtonItems representing the buttons in this platform's default selection menu for an editable field.
For example, EditableText uses this to generate the default buttons for its context menu.
See also:
- EditableTextState.contextMenuButtonItems, which gives the ContextMenuButtonItems for a specific EditableText.
- SelectableRegion.getSelectableButtonItems, which performs a similar role but for content that is selectable but not editable.
- AdaptiveTextSelectionToolbar, which builds the toolbar itself, and can take a list of ContextMenuButtonItems with AdaptiveTextSelectionToolbar.buttonItems.
- AdaptiveTextSelectionToolbar.getAdaptiveButtons, which builds the button Widgets for the current platform given ContextMenuButtonItems.
Implementation
static List<ContextMenuButtonItem> getEditableButtonItems({
required final ClipboardStatus? clipboardStatus,
required final VoidCallback? onCopy,
required final VoidCallback? onCut,
required final VoidCallback? onPaste,
required final VoidCallback? onSelectAll,
required final VoidCallback? onLookUp,
required final VoidCallback? onSearchWeb,
required final VoidCallback? onShare,
required final VoidCallback? onLiveTextInput,
}) {
final List<ContextMenuButtonItem> resultButtonItem = <ContextMenuButtonItem>[];
// Configure button items with clipboard.
if (onPaste == null || clipboardStatus != ClipboardStatus.unknown) {
// If the paste button is enabled, don't render anything until the state
// of the clipboard is known, since it's used to determine if paste is
// shown.
// On Android, the share button is before the select all button.
final bool showShareBeforeSelectAll = defaultTargetPlatform == TargetPlatform.android;
resultButtonItem.addAll(<ContextMenuButtonItem>[
if (onCut != null)
ContextMenuButtonItem(
onPressed: onCut,
type: ContextMenuButtonType.cut,
),
if (onCopy != null)
ContextMenuButtonItem(
onPressed: onCopy,
type: ContextMenuButtonType.copy,
),
if (onPaste != null)
ContextMenuButtonItem(
onPressed: onPaste,
type: ContextMenuButtonType.paste,
),
if (onShare != null && showShareBeforeSelectAll)
ContextMenuButtonItem(
onPressed: onShare,
type: ContextMenuButtonType.share,
),
if (onSelectAll != null)
ContextMenuButtonItem(
onPressed: onSelectAll,
type: ContextMenuButtonType.selectAll,
),
if (onLookUp != null)
ContextMenuButtonItem(
onPressed: onLookUp,
type: ContextMenuButtonType.lookUp,
),
if (onSearchWeb != null)
ContextMenuButtonItem(
onPressed: onSearchWeb,
type: ContextMenuButtonType.searchWeb,
),
if (onShare != null && !showShareBeforeSelectAll)
ContextMenuButtonItem(
onPressed: onShare,
type: ContextMenuButtonType.share,
),
]);
}
// Config button items with Live Text.
if (onLiveTextInput != null) {
resultButtonItem.add(ContextMenuButtonItem(
onPressed: onLiveTextInput,
type: ContextMenuButtonType.liveTextInput,
));
}
return resultButtonItem;
}