getAdaptiveButtons static method

Iterable<Widget> getAdaptiveButtons(
  1. BuildContext context,
  2. List<ContextMenuButtonItem> buttonItems
)

Returns a List of Widgets generated by turning buttonItems into the default context menu buttons for Cupertino on the current platform.

This is useful when building a text selection toolbar with the default button appearance for the given platform, but where the toolbar and/or the button actions and labels may be custom.

Does not build Material buttons. On non-Apple platforms, Cupertino buttons will still be used, because the Cupertino library does not access the Material library. To get the native-looking buttons on every platform, use AdaptiveTextSelectionToolbar.getAdaptiveButtons in the Material library.

See also:

Implementation

static Iterable<Widget> getAdaptiveButtons(BuildContext context, List<ContextMenuButtonItem> buttonItems) {
  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
    case TargetPlatform.fuchsia:
    case TargetPlatform.iOS:
      return buttonItems.map((ContextMenuButtonItem buttonItem) {
        return CupertinoTextSelectionToolbarButton.buttonItem(
          buttonItem: buttonItem,
        );
      });
    case TargetPlatform.linux:
    case TargetPlatform.windows:
    case TargetPlatform.macOS:
      return buttonItems.map((ContextMenuButtonItem buttonItem) {
        return CupertinoDesktopTextSelectionToolbarButton.buttonItem(
          buttonItem: buttonItem,
        );
      });
  }
}