FormBuilderDropdown<T> constructor

FormBuilderDropdown<T>({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<T>? validator,
  4. T? initialValue,
  5. InputDecoration decoration = const InputDecoration(),
  6. ValueChanged<T?>? onChanged,
  7. ValueTransformer<T?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<T>? onSaved,
  10. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  11. VoidCallback? onReset,
  12. FocusNode? focusNode,
  13. String? restorationId,
  14. FormFieldErrorBuilder? errorBuilder,
  15. required List<DropdownMenuItem<T>> items,
  16. bool isExpanded = true,
  17. bool isDense = true,
  18. int elevation = 8,
  19. double iconSize = 24.0,
  20. TextStyle? style,
  21. Widget? disabledHint,
  22. Widget? icon,
  23. Color? iconDisabledColor,
  24. Color? iconEnabledColor,
  25. VoidCallback? onTap,
  26. bool autofocus = false,
  27. Color? dropdownColor,
  28. Color? focusColor,
  29. double? itemHeight,
  30. DropdownButtonBuilder? selectedItemBuilder,
  31. double? menuMaxHeight,
  32. bool? enableFeedback,
  33. BorderRadius? borderRadius,
  34. AlignmentGeometry alignment = AlignmentDirectional.centerStart,
  35. Widget? hint,
  36. Widget? underline = const SizedBox.shrink(),
  37. EdgeInsetsGeometry? padding,
  38. double? menuWidth,
})

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,
           ),
         );
       },
     );