DropdownField<T, I extends Widget> constructor

DropdownField<T, I extends Widget>({
  1. String? labelPrefix,
  2. String? label,
  3. Widget? labelWidget,
  4. DropdownEditingController<T, I>? controller,
  5. FormFieldValidator<T?>? validator,
  6. FormFieldSetter<T>? onSaved,
  7. T? initialValue,
  8. Map<T, I>? items,
  9. bool enabled = true,
  10. AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
  11. dynamic onChanged(
    1. T? value
    )?,
  12. bool filled = false,
  13. Color? fillColor,
  14. DropdownButtonBuilder? selectedItemBuilder,
  15. Widget? hint,
  16. Widget? disabledHint,
  17. Color? focusColor,
  18. int elevation = 8,
  19. TextStyle? style,
  20. Widget? icon,
  21. Color? iconDisabledColor,
  22. Color? iconEnabledColor,
  23. double iconSize = 24.0,
  24. bool isDense = true,
  25. bool isExpanded = false,
  26. double? itemHeight,
  27. FocusNode? focusNode,
  28. bool autofocus = false,
  29. Color? dropdownColor,
  30. InputDecoration? decoration,
  31. EdgeInsets padding = const EdgeInsets.all(8),
  32. String? hintText,
  33. EdgeInsets? contentPadding,
  34. int? sizeExtraSmall,
  35. int? sizeSmall,
  36. int? sizeMedium,
  37. int? sizeLarge,
  38. int? sizeExtraLarge,
  39. double? minHeight,
  40. 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,
                      ),
                    ),
                  );
                },
              ),
            ),
          );
        },
      );