DropdownField<T, I extends Widget> constructor
DropdownField<T, I extends Widget> ({
- String? labelPrefix,
- String? label,
- Widget? labelWidget,
- DropdownEditingController<
T, I> ? controller, - FormFieldValidator<
T?> ? validator, - FormFieldSetter<
T> ? onSaved, - T? initialValue,
- Map<
T, I> ? items, - bool enabled = true,
- AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
- dynamic onChanged(
- T? value
- bool filled = false,
- Color? fillColor,
- DropdownButtonBuilder? selectedItemBuilder,
- Widget? hint,
- Widget? disabledHint,
- Color? focusColor,
- int elevation = 8,
- TextStyle? style,
- Widget? icon,
- Color? iconDisabledColor,
- Color? iconEnabledColor,
- double iconSize = 24.0,
- bool isDense = true,
- bool isExpanded = false,
- double? itemHeight,
- FocusNode? focusNode,
- bool autofocus = false,
- Color? dropdownColor,
- InputDecoration? decoration,
- EdgeInsets padding = const EdgeInsets.all(8),
- String? hintText,
- EdgeInsets? contentPadding,
- int? sizeExtraSmall,
- int? sizeSmall,
- int? sizeMedium,
- int? sizeLarge,
- int? sizeExtraLarge,
- double? minHeight,
- Key? key,
Implementation
DropdownField({
String? labelPrefix,
String? label,
Widget? labelWidget,
this.controller,
FormFieldValidator<T?>? validator,
super.onSaved,
T? initialValue,
this.items,
super.enabled,
AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
Function(T? value)? onChanged,
bool filled = false,
Color? fillColor,
DropdownButtonBuilder? selectedItemBuilder,
Widget? hint,
Widget? disabledHint,
Color? focusColor,
int elevation = 8,
TextStyle? style,
Widget? icon,
Color? iconDisabledColor,
Color? iconEnabledColor,
double iconSize = 24.0,
bool isDense = true,
bool isExpanded = false,
double? itemHeight,
FocusNode? focusNode,
bool autofocus = false,
Color? dropdownColor,
InputDecoration? decoration,
EdgeInsets padding = const EdgeInsets.all(8),
String? hintText,
EdgeInsets? contentPadding,
super.sizeExtraSmall,
super.sizeSmall,
super.sizeMedium,
super.sizeLarge,
super.sizeExtraLarge,
super.minHeight,
super.key,
}) : assert(
initialValue == null || controller == null,
'initialValue or controller must be null.',
),
// assert(elevation != null),
// assert(iconSize != null),
// assert(isDense != null),
// assert(isExpanded != null),
assert(
itemHeight == null || itemHeight >= kMinInteractiveDimension,
'itemHeight must be null or equal or greater '
'kMinInteractiveDimension.',
),
// assert(autofocus != null),
assert(
label == null || labelWidget == null,
'label or labelWidget must be null.',
),
super(
initialValue: controller != null ? controller.value : initialValue,
validator: enabled ? validator : (_) => null,
autovalidateMode: autoValidateMode,
builder: (FormFieldState<T?> field) {
_DropdownFieldState<T, I> state =
field as _DropdownFieldState<T, I>;
InputDecoration effectiveDecoration = (decoration ??
InputDecoration(
border: const OutlineInputBorder(),
filled: filled,
fillColor: fillColor,
label: labelWidget,
labelText: (labelPrefix?.isEmpty ?? true)
? label
: '$labelPrefix - $label',
counterText: '',
focusColor: focusColor,
hintText: hintText,
contentPadding: contentPadding,
))
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
return Padding(
padding: padding,
child: Focus(
canRequestFocus: false,
skipTraversal: true,
child: Builder(
builder: (BuildContext context) {
return InputDecorator(
decoration: effectiveDecoration.copyWith(
errorText: enabled ? field.errorText : null,
enabled: enabled,
),
isEmpty: state.value == null,
isFocused: Focus.of(context).hasFocus,
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
items: state._effectiveController.getDropdownItems(),
selectedItemBuilder: selectedItemBuilder,
value: state._effectiveController.value,
hint: hint,
disabledHint: disabledHint,
onChanged: enabled
? (T? value) {
state.didChange(value);
if (onChanged != null && state.isValid) {
onChanged(value);
}
}
: null,
// onTap: onTap,
elevation: elevation,
style: style,
icon: icon,
iconDisabledColor: iconDisabledColor,
iconEnabledColor: iconEnabledColor,
iconSize: iconSize,
isDense: isDense,
isExpanded: isExpanded,
itemHeight: itemHeight,
focusColor: focusColor,
focusNode: focusNode,
autofocus: autofocus,
dropdownColor: dropdownColor,
),
),
);
},
),
),
);
},
);