DropdownButton2<T> constructor

DropdownButton2<T>({
  1. Key? key,
  2. required List<DropdownMenuItem<T>>? items,
  3. DropdownButtonBuilder? selectedItemBuilder,
  4. T? value,
  5. Widget? hint,
  6. Widget? disabledHint,
  7. ValueChanged<T?>? onChanged,
  8. OnMenuStateChangeFn? onMenuStateChange,
  9. TextStyle? style,
  10. Widget? underline,
  11. bool isDense = false,
  12. bool isExpanded = false,
  13. FocusNode? focusNode,
  14. bool autofocus = false,
  15. bool? enableFeedback,
  16. AlignmentGeometry alignment = AlignmentDirectional.centerStart,
  17. ButtonStyleData? buttonStyleData,
  18. IconStyleData iconStyleData = const IconStyleData(),
  19. DropdownStyleData dropdownStyleData = const DropdownStyleData(),
  20. MenuItemStyleData menuItemStyleData = const MenuItemStyleData(),
  21. DropdownSearchData<T>? dropdownSearchData,
  22. Widget? customButton,
  23. bool openWithLongPress = false,
  24. bool barrierDismissible = true,
  25. Color? barrierColor,
  26. String? barrierLabel,
})

Creates a DropdownButton2. It's customizable DropdownButton with steady dropdown menu and many other features.

The items must have distinct values. If value isn't null then it must be equal to one of the DropdownMenuItem values. If items or onChanged is null, the button will be disabled, the down arrow 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.

Implementation

DropdownButton2({
  super.key,
  required this.items,
  this.selectedItemBuilder,
  this.value,
  this.hint,
  this.disabledHint,
  this.onChanged,
  this.onMenuStateChange,
  this.style,
  this.underline,
  this.isDense = false,
  this.isExpanded = false,
  this.focusNode,
  this.autofocus = false,
  this.enableFeedback,
  this.alignment = AlignmentDirectional.centerStart,
  this.buttonStyleData,
  this.iconStyleData = const IconStyleData(),
  this.dropdownStyleData = const DropdownStyleData(),
  this.menuItemStyleData = const MenuItemStyleData(),
  this.dropdownSearchData,
  this.customButton,
  this.openWithLongPress = false,
  this.barrierDismissible = true,
  this.barrierColor,
  this.barrierLabel,
  // When adding new arguments, consider adding similar arguments to
  // DropdownButtonFormField.
})  : assert(
        items == null ||
            items.isEmpty ||
            value == null ||
            items.where((DropdownMenuItem<T> item) {
                  return item.value == value;
                }).length ==
                1,
        "There should be exactly one item with [DropdownButton]'s value: "
        '$value. \n'
        'Either zero or 2 or more [DropdownMenuItem]s were detected '
        'with the same value',
      ),
      assert(
        menuItemStyleData.customHeights == null ||
            items == null ||
            items.isEmpty ||
            menuItemStyleData.customHeights?.length == items.length,
        'customHeights list should have the same length of items list',
      ),
      _inputDecoration = null,
      _isEmpty = false,
      _isFocused = false;