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. TextStyle? style,
  10. double? itemHeight = _kMinInteractiveDimension,
  11. FocusNode? focusNode,
  12. bool autofocus = false,
  13. Color? popupColor,
  14. double? menuMaxHeight,
  15. 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 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({
  super.key,
  required this.items,
  this.selectedItemBuilder,
  this.value,
  this.hint,
  this.disabledHint,
  required this.onChanged,
  this.onTap,
  this.style,
  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);