FormBuilderDropdown<T> constructor
FormBuilderDropdown<T> ({
- Key? key,
- required String name,
- FormFieldValidator<
T> ? validator, - T? initialValue,
- InputDecoration decoration = const InputDecoration(),
- ValueChanged<
T?> ? onChanged, - ValueTransformer<
T?> ? valueTransformer, - bool enabled = true,
- FormFieldSetter<
T> ? onSaved, - AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- String? restorationId,
- FormFieldErrorBuilder? errorBuilder,
- required List<
DropdownMenuItem< items,T> > - bool isExpanded = true,
- bool isDense = true,
- int elevation = 8,
- double iconSize = 24.0,
- TextStyle? style,
- Widget? disabledHint,
- Widget? icon,
- Color? iconDisabledColor,
- Color? iconEnabledColor,
- VoidCallback? onTap,
- bool autofocus = false,
- Color? dropdownColor,
- Color? focusColor,
- double? itemHeight,
- DropdownButtonBuilder? selectedItemBuilder,
- bool? enableFeedback,
- BorderRadius? borderRadius,
- AlignmentGeometry alignment = AlignmentDirectional.centerStart,
- Widget? hint,
- Widget? underline = const SizedBox.shrink(),
- EdgeInsetsGeometry? padding,
Creates field for Dropdown button
Implementation
FormBuilderDropdown({
super.key,
required super.name,
super.validator,
super.initialValue,
super.decoration,
super.onChanged,
super.valueTransformer,
super.enabled,
super.onSaved,
super.autovalidateMode = AutovalidateMode.disabled,
super.onReset,
super.focusNode,
super.restorationId,
super.errorBuilder,
required this.items,
this.isExpanded = true,
this.isDense = true,
this.elevation = 8,
this.iconSize = 24.0,
this.style,
this.disabledHint,
this.icon,
this.iconDisabledColor,
this.iconEnabledColor,
this.onTap,
this.autofocus = false,
this.dropdownColor,
this.focusColor,
this.itemHeight,
this.selectedItemBuilder,
this.menuMaxHeight,
this.enableFeedback,
this.borderRadius,
this.alignment = AlignmentDirectional.centerStart,
this.hint,
this.underline = const SizedBox.shrink(),
this.padding,
this.menuWidth,
}) : super(
builder: (FormFieldState<T?> field) {
final state = field as _FormBuilderDropdownState<T>;
final hasValue = items.map((e) => e.value).contains(field.value);
return InputDecorator(
decoration: state.decoration,
isEmpty: !hasValue,
child: DropdownButton<T>(
menuWidth: menuWidth,
padding: padding,
underline: underline,
isExpanded: isExpanded,
items: items,
value: hasValue ? field.value : null,
style: style,
isDense: isDense,
disabledHint: hasValue
? items
.firstWhere(
(dropDownItem) => dropDownItem.value == field.value,
)
.child
: disabledHint,
elevation: elevation,
iconSize: iconSize,
icon: icon,
iconDisabledColor: iconDisabledColor,
iconEnabledColor: iconEnabledColor,
onChanged: state.enabled
? (T? value) {
field.didChange(value);
}
: null,
onTap: onTap,
focusNode: state.effectiveFocusNode,
autofocus: autofocus,
dropdownColor: dropdownColor,
focusColor: focusColor,
itemHeight: itemHeight,
selectedItemBuilder: selectedItemBuilder,
menuMaxHeight: menuMaxHeight,
borderRadius: borderRadius,
enableFeedback: enableFeedback,
alignment: alignment,
hint: hint,
),
);
},
);