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,
- Widget? hint,
- TextStyle? style,
- Widget? disabledHint,
- Widget? icon,
- Color? iconDisabledColor,
- Color? iconEnabledColor,
- bool allowClear = false,
- Widget clearIcon = const Icon(Icons.close),
- VoidCallback? onTap,
- bool autofocus = false,
- Color? dropdownColor,
- Color? focusColor,
- double itemHeight = kMinInteractiveDimension,
- DropdownButtonBuilder? selectedItemBuilder,
Creates field for Dropdown button
Implementation
FormBuilderDropdown({
Key? key,
//From Super
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 this.items,
this.isExpanded = true,
this.isDense = true,
this.elevation = 8,
this.iconSize = 24.0,
this.hint,
this.style,
this.disabledHint,
this.icon,
this.iconDisabledColor,
this.iconEnabledColor,
this.allowClear = false,
this.clearIcon = const Icon(Icons.close),
this.onTap,
this.autofocus = false,
this.dropdownColor,
this.focusColor,
this.itemHeight = kMinInteractiveDimension,
this.selectedItemBuilder,
}) : /*: assert(allowClear == true || clearIcon != null)*/ super(
key: key,
initialValue: initialValue,
name: name,
validator: validator,
valueTransformer: valueTransformer,
onChanged: onChanged,
autovalidateMode: autovalidateMode,
onSaved: onSaved,
enabled: enabled,
onReset: onReset,
decoration: decoration,
focusNode: focusNode,
builder: (FormFieldState<T?> field) {
final state = field as _FormBuilderDropdownState<T>;
// DropdownButtonFormField
// TextFormField
void changeValue(T? value) {
state.requestFocus();
state.didChange(value);
}
return InputDecorator(
decoration: state.decoration.copyWith(
floatingLabelBehavior: hint == null
? decoration.floatingLabelBehavior
: FloatingLabelBehavior.always,
),
isEmpty: state.value == null,
child: Row(
children: <Widget>[
Expanded(
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
isExpanded: isExpanded,
hint: hint,
items: items,
value: field.value,
style: style,
isDense: isDense,
disabledHint: field.value != null
? (items
.firstWhereOrNull(
(val) => val.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,
),
),
),
if (allowClear && state.enabled && field.value != null) ...[
const VerticalDivider(),
InkWell(
onTap: () => changeValue(null),
child: clearIcon,
),
]
],
),
);
},
);