ComboboxFormField<T> constructor

ComboboxFormField<T>({
  1. Key? key,
  2. required List<ComboBoxItem<T>>? items,
  3. ComboBoxBuilder? selectedItemBuilder,
  4. T? value,
  5. Widget? placeholder,
  6. Widget? disabledPlaceholder,
  7. required ValueChanged<T?>? onChanged,
  8. VoidCallback? onTap,
  9. int elevation = 8,
  10. TextStyle? style,
  11. Widget icon = const Icon(FluentIcons.chevron_down),
  12. Color? iconDisabledColor,
  13. Color? iconEnabledColor,
  14. double iconSize = 8.0,
  15. bool isExpanded = false,
  16. Color? focusColor,
  17. FocusNode? focusNode,
  18. bool autofocus = false,
  19. Color? popupColor,
  20. FormFieldSetter<T>? onSaved,
  21. FormFieldValidator<T>? validator,
  22. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  23. double? menuMaxHeight,
  24. bool? enableFeedback,
  25. AlignmentGeometry alignment = AlignmentDirectional.centerStart,
  26. BorderRadius? borderRadius,
})

Creates a ComboBox widget that is a FormField

For a description of the onSaved, validator, or autovalidateMode parameters, see FormField. For the rest, see ComboBox.

The items, elevation, iconSize, isExpanded and autofocus parameters must not be null.

Implementation

ComboboxFormField({
  super.key,
  required List<ComboBoxItem<T>>? items,
  ComboBoxBuilder? selectedItemBuilder,
  T? value,
  Widget? placeholder,
  Widget? disabledPlaceholder,
  required this.onChanged,
  VoidCallback? onTap,
  int elevation = 8,
  TextStyle? style,
  Widget icon = const Icon(FluentIcons.chevron_down),
  Color? iconDisabledColor,
  Color? iconEnabledColor,
  double iconSize = 8.0,
  bool isExpanded = false,
  Color? focusColor,
  FocusNode? focusNode,
  bool autofocus = false,
  Color? popupColor,
  super.onSaved,
  super.validator,
  super.autovalidateMode = AutovalidateMode.disabled,
  double? menuMaxHeight,
  bool? enableFeedback,
  AlignmentGeometry alignment = AlignmentDirectional.centerStart,
  BorderRadius? borderRadius,
  // When adding new arguments, consider adding similar arguments to
  // ComboBox.
}) : super(
        initialValue: value,
        builder: (FormFieldState<T> field) {
          final state = field as _ComboboxFormFieldState<T>;

          // An unfocusable Focus widget so that this widget can detect if its
          // descendants have focus or not.
          return Focus(
            canRequestFocus: false,
            skipTraversal: true,
            child: Builder(builder: (BuildContext context) {
              return FormRow(
                padding: EdgeInsets.zero,
                error:
                    field.errorText != null ? Text(field.errorText!) : null,
                child: Align(
                  alignment: AlignmentDirectional.centerStart,
                  child: ComboBox<T>(
                    items: items,
                    selectedItemBuilder: selectedItemBuilder,
                    value: state.value,
                    placeholder: placeholder,
                    disabledPlaceholder: disabledPlaceholder,
                    onChanged: onChanged == null ? null : state.didChange,
                    onTap: onTap,
                    elevation: elevation,
                    style: style,
                    icon: icon,
                    iconDisabledColor: iconDisabledColor,
                    iconEnabledColor: iconEnabledColor,
                    iconSize: iconSize,
                    isExpanded: isExpanded,
                    focusColor: focusColor,
                    focusNode: focusNode,
                    autofocus: autofocus,
                    popupColor: popupColor,
                  ),
                ),
              );
            }),
          );
        },
      );