TxDropdownFormField<T, V> constructor

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

Implementation

TxDropdownFormField({
  required List<T> source,
  required ValueMapper<T, String?> labelMapper,
  ValueMapper<T, V?>? valueMapper,
  IndexedValueMapper<T, bool>? enabledMapper,
  T? initialData,
  V? initialValue,
  super.key,
  super.onSaved,
  FormFieldValidator<T>? validator,
  super.enabled,
  super.autovalidateMode,
  super.restorationId,
  super.decoration,
  super.onChanged,
  super.required,
  super.bordered,
  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(
        initialValue: TxPickerFormField.initData(
          source,
          initialData,
          initialValue,
          valueMapper,
        ),
        builder: (field) {
          final AlignmentGeometry effectiveAlign = alignment ??
              (layoutDirection == Axis.horizontal
                  ? Alignment.centerRight
                  : Alignment.centerLeft);

          return DropdownButtonFormField<T>(
            items: List.generate(
              source.length,
              (i) {
                final T item = source[i];
                final bool enabled =
                    enabledMapper == null ? true : enabledMapper(i, item);
                return DropdownMenuItem<T>(
                  value: item,
                  alignment: effectiveAlign,
                  enabled: enabled,
                  child: Text(
                    labelMapper(item) ?? '',
                    style: enabled
                        ? null
                        : TextStyle(
                            color: Theme.of(field.context).disabledColor,
                          ),
                  ),
                );
              },
            ),
            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),
      );