buttonMenu method

Widget buttonMenu({
  1. Key? key,
  2. List<T>? items,
  3. PopupMenuItemBuilder<T>? itemBuilder,
  4. T? initialValue,
  5. PopupMenuItemSelected<T>? onSelected,
  6. PopupMenuCanceled? onCanceled,
  7. String? tooltip,
  8. double? elevation,
  9. EdgeInsetsGeometry? padding,
  10. Widget? child,
  11. Widget? icon,
  12. Offset? offset,
  13. bool? enabled,
  14. ShapeBorder? shape,
  15. Color? color,
  16. bool? captureInheritedThemes,
})

Implementation

// Returning a widget allows for the Builder() widget below.
Widget buttonMenu({
  Key? key,
  List<T>? items,
  PopupMenuItemBuilder<T>? itemBuilder,
  T? initialValue,
  PopupMenuItemSelected<T>? onSelected,
  PopupMenuCanceled? onCanceled,
  String? tooltip,
  double? elevation,
  EdgeInsetsGeometry? padding,
  Widget? child,
  Widget? icon,
  Offset? offset,
  bool? enabled,
  ShapeBorder? shape,
  Color? color,
  bool? captureInheritedThemes,
}) {
  // So to retrieve the Scaffold object if any.
  return Builder(builder: (context) {
    this.context ??= context;
    items ??= this.items;
    Widget popupMenu = PopupMenuButton<T>(
      key: key ?? this.key,
      itemBuilder: itemBuilder ??
          (items != null && items!.isNotEmpty
              ? _onItems(items)
              : this.itemBuilder) ??
          onItemBuilder,
      initialValue: initialValue ?? this.initialValue ?? onInitialValue(),
      onSelected: onSelected ?? this.onSelected ?? onSelection,
      onCanceled: onCanceled ?? this.onCanceled ?? onCancellation,
      tooltip: tooltip ?? this.tooltip ?? onTooltip(),
      elevation: elevation ?? this.elevation ?? onElevation(),
      padding:
          padding ?? this.padding ?? onPadding() ?? const EdgeInsets.all(8),
      icon: icon ?? this.icon ?? onIcon(),
      offset: offset ?? this.offset ?? onOffset() ?? Offset.zero,
      enabled: enabled ?? this.enabled ?? onEnabled() ?? true,
      shape: shape ?? this.shape ?? onShape(),
      color: color ?? this.color ?? onColor(),
      child: child ?? this.child ?? onChild(),
    );
    // If not running under the MaterialApp widget.
    if (context.widget is! Material &&
        context.findAncestorWidgetOfExactType<Material>() == null) {
      popupMenu = Material(child: popupMenu);
    }
    return popupMenu;
  });
}