getEditableButtonItems static method

List<ContextMenuButtonItem> getEditableButtonItems({
  1. required ClipboardStatus? clipboardStatus,
  2. required VoidCallback? onCopy,
  3. required VoidCallback? onCut,
  4. required VoidCallback? onPaste,
  5. required VoidCallback? onSelectAll,
  6. required VoidCallback? onLookUp,
  7. required VoidCallback? onSearchWeb,
  8. required VoidCallback? onShare,
  9. 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:

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;
}