TxDropdownFormField<T, V>.custom constructor

TxDropdownFormField<T, V>.custom({
  1. required List<DropdownMenuItem<T>> items,
  2. Key? key,
  3. T? initialValue,
  4. FormFieldSetter<T>? onSaved,
  5. FormFieldValidator<T>? validator,
  6. bool? enabled,
  7. AutovalidateMode? autovalidateMode = AutovalidateMode.onUserInteraction,
  8. String? restorationId,
  9. InputDecoration? decoration,
  10. ValueChanged<T?>? onChanged,
  11. bool? required,
  12. FocusNode? focusNode,
  13. String? hintText,
  14. Widget? hint,
  15. Widget? disabledHint,
  16. VoidCallback? onTap,
  17. int? elevation,
  18. TextStyle? style,
  19. Widget? icon,
  20. Color? iconDisabledColor,
  21. Color? iconEnabledColor,
  22. double? iconSize,
  23. bool? isDense,
  24. bool? isExpanded,
  25. double? itemHeight,
  26. Color? focusColor,
  27. bool? autofocus,
  28. Color? dropdownColor,
  29. double? menuMaxHeight,
  30. bool? enableFeedback,
  31. AlignmentGeometry? alignment,
  32. BorderRadius? borderRadius,
  33. EdgeInsetsGeometry? menuPadding,
  34. DropdownButtonBuilder? selectedItemBuilder,
  35. Widget? label,
  36. String? labelText,
  37. TextAlign? labelTextAlign,
  38. TextOverflow? labelOverflow,
  39. EdgeInsetsGeometry? padding,
  40. FieldActionsBuilder<T>? actionsBuilder,
  41. TextStyle? labelStyle,
  42. double? horizontalGap,
  43. Color? tileColor,
  44. Axis? layoutDirection,
  45. TxFormFieldBuilder<T>? trailingBuilder,
  46. Widget? leading,
  47. VisualDensity? visualDensity,
  48. ShapeBorder? shape,
  49. Color? iconColor,
  50. Color? textColor,
  51. TextStyle? leadingAndTrailingTextStyle,
  52. double? minLeadingWidth,
  53. bool? dense,
  54. bool? colon,
  55. double? minLabelWidth,
  56. double? minVerticalPadding,
})

Implementation

TxDropdownFormField.custom({
  required List<DropdownMenuItem<T>> items,
  super.key,
  super.initialValue,
  super.onSaved,
  FormFieldValidator<T>? validator,
  super.enabled,
  super.autovalidateMode,
  super.restorationId,
  super.decoration,
  super.onChanged,
  super.required,
  FocusNode? focusNode,
  String? hintText,
  Widget? hint,
  Widget? disabledHint,
  VoidCallback? onTap,
  int? elevation,
  TextStyle? style,
  Widget? icon,
  Color? iconDisabledColor,
  Color? iconEnabledColor,
  double? iconSize,
  bool? isDense,
  bool? isExpanded,
  double? itemHeight,
  Color? focusColor,
  bool? autofocus,
  Color? dropdownColor,
  double? menuMaxHeight,
  bool? enableFeedback,
  AlignmentGeometry? alignment,
  BorderRadius? borderRadius,
  EdgeInsetsGeometry? menuPadding,
  DropdownButtonBuilder? selectedItemBuilder,
  super.label,
  super.labelText,
  super.labelTextAlign,
  super.labelOverflow,
  super.padding,
  super.actionsBuilder,
  super.labelStyle,
  super.horizontalGap,
  super.tileColor,
  super.layoutDirection,
  super.trailingBuilder,
  super.leading,
  super.visualDensity,
  super.shape,
  super.iconColor,
  super.textColor,
  super.leadingAndTrailingTextStyle,
  super.minLeadingWidth,
  super.dense,
  super.colon,
  super.minLabelWidth,
  super.minVerticalPadding,
}) : super(
        builder: (field) {
          final AlignmentGeometry effectiveAlign = alignment ??
              (layoutDirection == Axis.horizontal
                  ? Alignment.centerRight
                  : Alignment.centerLeft);

          return DropdownButtonFormField<T>(
            items: items,
            selectedItemBuilder: selectedItemBuilder,
            value: field.value,
            hint: hint ?? Text(hintText ?? '请选择'),
            disabledHint: disabledHint ?? const Text('无'),
            onChanged: field.didChange,
            onTap: onTap,
            elevation: elevation ?? 4,
            style: style ?? Theme.of(field.context).textTheme.bodyLarge,
            icon: icon,
            iconDisabledColor: iconDisabledColor,
            iconEnabledColor: iconEnabledColor,
            iconSize: iconSize ?? 24.0,
            isDense: isDense ?? true,
            isExpanded: isExpanded ?? true,
            itemHeight: itemHeight,
            focusColor: focusColor,
            focusNode: focusNode,
            autofocus: autofocus ?? false,
            dropdownColor: dropdownColor,
            decoration: field.effectiveDecoration,
            menuMaxHeight: menuMaxHeight,
            enableFeedback: enableFeedback,
            alignment: effectiveAlign,
            borderRadius: borderRadius,
            padding: menuPadding,
          );
        },
        validator: (val) =>
            TxPickerFormField.generateValidator(val, validator, required),
        hintText: hintText ?? '请选择',
      );