DropdownButton<T> constructor Null safety

DropdownButton<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. VoidCallback? onTap,
  9. int elevation,
  10. TextStyle? style,
  11. Widget? underline,
  12. Widget? icon,
  13. Color? iconDisabledColor,
  14. Color? iconEnabledColor,
  15. double iconSize,
  16. bool isDense,
  17. bool isExpanded,
  18. double? itemHeight,
  19. Color? focusColor,
  20. FocusNode? focusNode,
  21. bool autofocus,
  22. Color? dropdownColor,
  23. double? menuMaxHeight,
  24. bool? enableFeedback,
  25. AlignmentGeometry alignment,
  26. BorderRadius? borderRadius}
)

Creates a dropdown button.

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.

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 dropdownColor argument specifies the background color of the dropdown when it is open. If it is null, the current theme's ThemeData.canvasColor will be used instead.

Implementation

DropdownButton({
  Key? key,
  required this.items,
  this.selectedItemBuilder,
  this.value,
  this.hint,
  this.disabledHint,
  this.onChanged,
  this.onTap,
  this.elevation = 8,
  this.style,
  this.underline,
  this.icon,
  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.dropdownColor,
  this.menuMaxHeight,
  this.enableFeedback,
  this.alignment = AlignmentDirectional.centerStart,
  this.borderRadius,
  // 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(elevation != null),
     assert(iconSize != null),
     assert(isDense != null),
     assert(isExpanded != null),
     assert(autofocus != null),
     assert(itemHeight == null || itemHeight >=  kMinInteractiveDimension),
     super(key: key);