DropdownButton2<T> constructor Null safety

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. int dropdownElevation = 8,
  10. TextStyle? style,
  11. Widget? underline,
  12. Widget? icon,
  13. Widget? iconOnClick,
  14. Color? iconDisabledColor,
  15. Color? iconEnabledColor,
  16. double iconSize = 24.0,
  17. bool isDense = false,
  18. bool isExpanded = false,
  19. double itemHeight = kMinInteractiveDimension,
  20. Color? focusColor,
  21. FocusNode? focusNode,
  22. bool autofocus = false,
  23. double? dropdownMaxHeight,
  24. bool? enableFeedback,
  25. AlignmentGeometry alignment = AlignmentDirectional.centerStart,
  26. double? buttonHeight,
  27. double? buttonWidth,
  28. EdgeInsetsGeometry? buttonPadding,
  29. BoxDecoration? buttonDecoration,
  30. int? buttonElevation,
  31. EdgeInsetsGeometry? itemPadding,
  32. double? dropdownWidth,
  33. EdgeInsetsGeometry? dropdownPadding,
  34. EdgeInsetsGeometry? dropdownScrollPadding,
  35. BoxDecoration? dropdownDecoration,
  36. Color? selectedItemHighlightColor,
  37. Radius? scrollbarRadius,
  38. double? scrollbarThickness,
  39. bool? scrollbarAlwaysShow,
  40. Offset? offset,
  41. Widget? customButton,
  42. List<double>? customItemsHeights,
  43. bool openWithLongPress = false,
  44. bool dropdownOverButton = false,
  45. bool dropdownFullScreen = false,
  46. bool barrierDismissible = true,
  47. Color? barrierColor,
  48. String? barrierLabel,
  49. TextEditingController? searchController,
  50. Widget? searchInnerWidget,
  51. _SearchMatchFn? searchMatchFn}
)

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.dropdownElevation = 8,
  this.style,
  this.underline,
  this.icon,
  this.iconOnClick,
  this.iconDisabledColor,
  this.iconEnabledColor,
  this.iconSize = 24.0,
  this.isDense = false,
  this.isExpanded = false,
  this.itemHeight = kMinInteractiveDimension,
  this.focusColor,
  this.focusNode,
  this.autofocus = false,
  this.dropdownMaxHeight,
  this.enableFeedback,
  this.alignment = AlignmentDirectional.centerStart,
  this.buttonHeight,
  this.buttonWidth,
  this.buttonPadding,
  this.buttonDecoration,
  this.buttonElevation,
  this.itemPadding,
  this.dropdownWidth,
  this.dropdownPadding,
  this.dropdownScrollPadding,
  this.dropdownDecoration,
  this.selectedItemHighlightColor,
  this.scrollbarRadius,
  this.scrollbarThickness,
  this.scrollbarAlwaysShow,
  this.offset,
  this.customButton,
  this.customItemsHeights,
  this.openWithLongPress = false,
  this.dropdownOverButton = false,
  this.dropdownFullScreen = false,
  this.barrierDismissible = true,
  this.barrierColor,
  this.barrierLabel,
  this.searchController,
  this.searchInnerWidget,
  this.searchMatchFn,
  // 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(
        customItemsHeights == null ||
            items == null ||
            items.isEmpty ||
            customItemsHeights.length == items.length,
        "customItemsHeights list should have the same length of items list",
      ),
      formFieldCallBack = null;