TxPickerFormField<T, V> constructor

TxPickerFormField<T, V>({
  1. required List<T> source,
  2. required ValueMapper<T, String?> labelMapper,
  3. bool? clearable,
  4. Key? key,
  5. FormFieldSetter<T>? onSaved,
  6. FormFieldValidator<T>? validator,
  7. bool? enabled,
  8. AutovalidateMode? autovalidateMode = AutovalidateMode.onUserInteraction,
  9. String? restorationId,
  10. InputDecoration? decoration,
  11. ValueChanged<T?>? onChanged,
  12. bool? required,
  13. ValueMapper<T, V?>? valueMapper,
  14. DataWidgetBuilder<T>? subtitleBuilder,
  15. PickerItemBuilder<T>? itemBuilder,
  16. ValueMapper<T, bool>? disabledWhen,
  17. T? initialData,
  18. V? initialValue,
  19. bool? showSearchField,
  20. Widget? placeholder,
  21. ListTileThemeData? listTileTheme,
  22. FocusNode? focusNode,
  23. String? hintText,
  24. TextAlign? textAlign,
  25. bool? bordered,
  26. TextEditingController? controller,
  27. UndoHistoryController? undoController,
  28. TextInputType? keyboardType,
  29. TextInputAction? textInputAction,
  30. TextCapitalization? textCapitalization,
  31. TextStyle? style,
  32. StrutStyle? strutStyle,
  33. TextAlignVertical? textAlignVertical,
  34. TextDirection? textDirection,
  35. bool? readOnly,
  36. bool? inputEnabled,
  37. bool? showCursor,
  38. bool? autofocus,
  39. MaterialStatesController? statesController,
  40. String? obscuringCharacter,
  41. bool? obscureText,
  42. bool? autocorrect,
  43. SmartDashesType? smartDashesType,
  44. SmartQuotesType? smartQuotesType,
  45. bool? enableSuggestions,
  46. int? maxLines,
  47. int? minLines,
  48. bool? expands,
  49. int? maxLength,
  50. MaxLengthEnforcement? maxLengthEnforcement,
  51. VoidCallback? onEditingComplete,
  52. ValueChanged<String>? onFieldSubmitted,
  53. AppPrivateCommandCallback? onAppPrivateCommand,
  54. List<TextInputFormatter>? inputFormatters,
  55. double? cursorWidth,
  56. double? cursorHeight,
  57. Radius? cursorRadius,
  58. bool? cursorOpacityAnimates,
  59. Color? cursorColor,
  60. Color? cursorErrorColor,
  61. BoxHeightStyle? selectionHeightStyle,
  62. BoxWidthStyle? selectionWidthStyle,
  63. Brightness? keyboardAppearance,
  64. EdgeInsets? scrollPadding,
  65. DragStartBehavior? dragStartBehavior,
  66. bool? enableInteractiveSelection,
  67. TextSelectionControls? selectionControls,
  68. GestureTapCallback? onTap,
  69. bool? onTapAlwaysCalled,
  70. TapRegionCallback? onTapOutside,
  71. MouseCursor? mouseCursor,
  72. InputCounterWidgetBuilder? buildCounter,
  73. ScrollController? scrollController,
  74. ScrollPhysics? scrollPhysics,
  75. Iterable<String>? autofillHints,
  76. ContentInsertionConfiguration? contentInsertionConfiguration,
  77. Clip? clipBehavior,
  78. bool? scribbleEnabled,
  79. bool? enableIMEPersonalizedLearning,
  80. EditableTextContextMenuBuilder? contextMenuBuilder,
  81. bool? canRequestFocus,
  82. SpellCheckConfiguration? spellCheckConfiguration,
  83. TextMagnifierConfiguration? magnifierConfiguration,
  84. Widget? label,
  85. String? labelText,
  86. TextAlign? labelTextAlign,
  87. TextOverflow? labelOverflow,
  88. EdgeInsetsGeometry? padding,
  89. FieldActionsBuilder<T>? actionsBuilder,
  90. TextStyle? labelStyle,
  91. double? horizontalGap,
  92. Color? tileColor,
  93. Axis? layoutDirection,
  94. TxFormFieldBuilder<T>? trailingBuilder,
  95. Widget? leading,
  96. VisualDensity? visualDensity,
  97. ShapeBorder? shape,
  98. Color? iconColor,
  99. Color? textColor,
  100. TextStyle? leadingAndTrailingTextStyle,
  101. double? minLeadingWidth,
  102. double? minLabelWidth,
  103. double? minVerticalPadding,
  104. bool? dense,
  105. bool? colon,
  106. Color? focusColor,
})

Implementation

TxPickerFormField({
  required List<T> source,
  required ValueMapper<T, String?> labelMapper,
  super.clearable,
  super.key,
  super.onSaved,
  FormFieldValidator<T>? validator,
  super.enabled,
  super.autovalidateMode,
  super.restorationId,
  super.decoration,
  super.onChanged,
  super.required,
  ValueMapper<T, V?>? valueMapper,
  DataWidgetBuilder<T>? subtitleBuilder,
  PickerItemBuilder<T>? itemBuilder,
  ValueMapper<T, bool>? disabledWhen,
  T? initialData,
  V? initialValue,
  bool? showSearchField,
  Widget? placeholder,
  ListTileThemeData? listTileTheme,
  super.focusNode,
  String? hintText,
  super.textAlign,
  super.bordered,
  super.controller,
  super.undoController,
  super.keyboardType,
  super.textInputAction,
  super.textCapitalization,
  super.style,
  super.strutStyle,
  super.textAlignVertical,
  super.textDirection,
  bool? readOnly,
  bool? inputEnabled,
  super.showCursor,
  super.autofocus,
  super.statesController,
  super.obscuringCharacter,
  super.obscureText,
  super.autocorrect,
  super.smartDashesType,
  super.smartQuotesType,
  super.enableSuggestions,
  super.maxLines,
  super.minLines,
  super.expands,
  super.maxLength,
  super.maxLengthEnforcement,
  super.onEditingComplete,
  super.onFieldSubmitted,
  super.onAppPrivateCommand,
  super.inputFormatters,
  super.cursorWidth,
  super.cursorHeight,
  super.cursorRadius,
  super.cursorOpacityAnimates,
  super.cursorColor,
  super.cursorErrorColor,
  super.selectionHeightStyle,
  super.selectionWidthStyle,
  super.keyboardAppearance,
  super.scrollPadding,
  super.dragStartBehavior,
  super.enableInteractiveSelection,
  super.selectionControls,
  super.onTap,
  super.onTapAlwaysCalled,
  super.onTapOutside,
  super.mouseCursor,
  super.buildCounter,
  super.scrollController,
  super.scrollPhysics,
  super.autofillHints,
  super.contentInsertionConfiguration,
  super.clipBehavior,
  super.scribbleEnabled,
  super.enableIMEPersonalizedLearning,
  super.contextMenuBuilder,
  super.canRequestFocus,
  super.spellCheckConfiguration,
  super.magnifierConfiguration,
  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.minLabelWidth,
  super.minVerticalPadding,
  super.dense,
  super.colon,
  super.focusColor,
})  : _readOnly = readOnly ?? false,
      inputEnabled = inputEnabled ?? false,
      super(
        initialValue:
            initData<T, V>(source, initialData, initialValue, valueMapper),
        onFieldTap: readOnly == true
            ? null
            : (field) => _onTap(
                  field,
                  (context, value) => showPickerBottomSheet<T, V>(
                    context,
                    source: readOnly == true
                        ? source
                        : <T>{
                            ...source,
                            if (field.value != null) field.value!
                          }.toList(),
                    labelMapper: labelMapper,
                    valueMapper: valueMapper,
                    initialData: value,
                    disabledWhen: disabledWhen,
                    title: labelText,
                    subtitleBuilder: subtitleBuilder,
                    itemBuilder: itemBuilder,
                    showSearchField: showSearchField,
                    placeholder: placeholder,
                    listTileTheme: listTileTheme,
                  ),
                ),
        readOnly: inputEnabled != true || readOnly == true,
        onInputChanged: (field, text) => _onInputChanged<T>(
          field,
          text,
          inputEnabled,
        ),
        displayTextMapper: (context, val) => labelMapper(val) ?? '',
        hintText: readOnly == true
            ? null
            : hintText ?? (inputEnabled == true ? '请选择或输入' : '请选择'),
        validator: readOnly == true
            ? null
            : (val) => generateValidator(val, validator, required),
      );