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,
- required List<
DropdownMenuItem< items,T> > - bool isExpanded = true,
- bool isDense = true,
- int elevation = 8,
- double iconSize = 24.0,
- @Deprecated('Please use decoration.hint and variations to set your desired label') Widget? hint,
- TextStyle? style,
- Widget? disabledHint,
- Widget? icon,
- Color? iconDisabledColor,
- Color? iconEnabledColor,
- @Deprecated('Please use decoration.suffix to set your desired behavior') bool allowClear = false,
- @Deprecated('Please use decoration.suffixIcon to set your desired icon') Widget clearIcon = const Icon(Icons.close),
- VoidCallback? onTap,
- bool autofocus = false,
- bool shouldRequestFocus = false,
- Color? dropdownColor,
- Color? focusColor,
- double? itemHeight,
- DropdownButtonBuilder? selectedItemBuilder,
- bool? enableFeedback,
- BorderRadius? borderRadius,
- AlignmentGeometry alignment = AlignmentDirectional.centerStart,
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,
required this.items,
this.isExpanded = true,
this.isDense = true,
this.elevation = 8,
this.iconSize = 24.0,
@Deprecated('Please use decoration.hint and variations to set your desired label')
this.hint,
this.style,
this.disabledHint,
this.icon,
this.iconDisabledColor,
this.iconEnabledColor,
@Deprecated('Please use decoration.suffix to set your desired behavior')
this.allowClear = false,
@Deprecated('Please use decoration.suffixIcon to set your desired icon')
this.clearIcon = const Icon(Icons.close),
this.onTap,
this.autofocus = false,
this.shouldRequestFocus = false,
this.dropdownColor,
this.focusColor,
this.itemHeight,
this.selectedItemBuilder,
this.menuMaxHeight,
this.enableFeedback,
this.borderRadius,
this.alignment = AlignmentDirectional.centerStart,
}) : super(
builder: (FormFieldState<T?> field) {
final state = field as _FormBuilderDropdownState<T>;
void changeValue(T? value) {
if (shouldRequestFocus) {
state.requestFocus();
}
state.didChange(value);
}
return InputDecorator(
decoration: state.decoration,
isEmpty: state.value == null,
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
isExpanded: isExpanded,
hint: hint,
items: items,
value: field.value,
style: style,
isDense: isDense,
disabledHint: field.value != null
? (items
.firstWhereOrNull((dropDownItem) =>
dropDownItem.value == field.value)
?.child ??
Text(field.value.toString()))
: disabledHint,
elevation: elevation,
iconSize: iconSize,
icon: icon,
iconDisabledColor: iconDisabledColor,
iconEnabledColor: iconEnabledColor,
onChanged:
state.enabled ? (value) => changeValue(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,
),
),
);
},
);