MacosPopupButton<T> constructor

MacosPopupButton<T>({
  1. Key? key,
  2. required List<MacosPopupMenuItem<T>>? items,
  3. MacosPopupButtonBuilder? selectedItemBuilder,
  4. T? value,
  5. Widget? hint,
  6. Widget? disabledHint,
  7. required ValueChanged<T?>? onChanged,
  8. VoidCallback? onTap,
  9. int elevation = 8,
  10. TextStyle? style,
  11. Color? iconDisabledColor,
  12. Color? iconEnabledColor,
  13. double? itemHeight = _kMinInteractiveDimension,
  14. FocusNode? focusNode,
  15. bool autofocus = false,
  16. Color? popupColor,
  17. double? menuMaxHeight,
  18. AlignmentGeometry alignment = AlignmentDirectional.centerStart,
})

Creates a macOS-style popup button.

The items must have distinct values. If value isn't null then it must be equal to one of the MacosPopupMenuItem values. If items or onChanged is null, the button will be disabled, the up-down caret icon will be greyed out.

If value is null and the button is enabled, hint will be displayed if it is non-null.

If value is null and the button is disabled, disabledHint will be displayed if it is non-null. If disabledHint is null, then hint will be displayed if it is non-null.

The elevation and iconSize arguments must not be null (they both have defaults, so do not need to be specified). The boolean isDense and isExpanded arguments must not be null.

The autofocus argument must not be null.

The popupColor argument specifies the background color of the popup when it is open. If it is null, the appropriate macOS canvas color will be used.

Implementation

MacosPopupButton({
  Key? key,
  required this.items,
  this.selectedItemBuilder,
  this.value,
  this.hint,
  this.disabledHint,
  required this.onChanged,
  this.onTap,
  this.elevation = 8,
  this.style,
  this.iconDisabledColor,
  this.iconEnabledColor,
  this.itemHeight = _kMinInteractiveDimension,
  this.focusNode,
  this.autofocus = false,
  this.popupColor,
  this.menuMaxHeight,
  this.alignment = AlignmentDirectional.centerStart,
})  : assert(
        items == null ||
            items.isEmpty ||
            value == null ||
            items.where((MacosPopupMenuItem<T> item) {
                  return item.value == value;
                }).length ==
                1,
        "There should be exactly one item with [MacosPopupButton]'s value: "
        '$value. \n'
        'Either zero or 2 or more [MacosPopupMenuItem]s were detected '
        'with the same value',
      ),
      assert(itemHeight == null || itemHeight >= _kMinInteractiveDimension),
      super(key: key);