ReactiveMacosTextField<T> constructor

ReactiveMacosTextField<T>({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<T>? formControl,
  4. Map<String, ValidationMessageFunction>? validationMessages,
  5. ControlValueAccessor<T, String>? valueAccessor,
  6. ShowErrorsFunction<T>? showErrors,
  7. BoxDecoration decoration = _kDefaultRoundedBorderDecoration,
  8. InputDecoration inputDecoration = const InputDecoration(border: InputBorder.none, contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0), isDense: true, isCollapsed: true),
  9. BoxDecoration focusedDecoration = _kDefaultFocusedBorderDecoration,
  10. EdgeInsets padding = const EdgeInsets.all(6.0),
  11. String? placeholder,
  12. TextStyle placeholderStyle = const TextStyle(fontWeight: FontWeight.w400, color: CupertinoColors.placeholderText),
  13. TextInputType? keyboardType,
  14. TextCapitalization textCapitalization = TextCapitalization.none,
  15. TextInputAction? textInputAction,
  16. TextStyle? style,
  17. StrutStyle? strutStyle,
  18. TextDirection? textDirection,
  19. TextAlign textAlign = TextAlign.start,
  20. TextAlignVertical? textAlignVertical,
  21. bool autofocus = false,
  22. bool readOnly = false,
  23. bool? showCursor,
  24. bool obscureText = false,
  25. String obscuringCharacter = '•',
  26. bool autocorrect = true,
  27. SmartDashesType? smartDashesType,
  28. SmartQuotesType? smartQuotesType,
  29. bool enableSuggestions = true,
  30. MaxLengthEnforcement? maxLengthEnforcement,
  31. int? maxLines = 1,
  32. int? minLines,
  33. bool expands = false,
  34. int? maxLength,
  35. GestureTapCallback? onTap,
  36. VoidCallback? onEditingComplete,
  37. List<TextInputFormatter>? inputFormatters,
  38. double cursorWidth = 2.0,
  39. double? cursorHeight,
  40. Radius cursorRadius = const Radius.circular(2.0),
  41. Color? cursorColor,
  42. Brightness? keyboardAppearance,
  43. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  44. bool enableInteractiveSelection = true,
  45. InputCounterWidgetBuilder? buildCounter,
  46. ScrollPhysics? scrollPhysics,
  47. ValueChanged<String>? onSubmitted,
  48. FocusNode? focusNode,
  49. Iterable<String>? autofillHints,
  50. MouseCursor? mouseCursor,
  51. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  52. AppPrivateCommandCallback? onAppPrivateCommand,
  53. String? restorationId,
  54. ScrollController? scrollController,
  55. TextSelectionControls? selectionControls,
  56. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  57. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  58. Widget? prefix,
  59. OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
  60. Widget? suffix,
  61. OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
  62. OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never,
})

Creates a ReactiveMacosTextField that contains a MacosTextField.

Can optionally provide a formControl to bind this widget to a control.

Can optionally provide a formControlName to bind this ReactiveFormField to a FormControl.

Must provide one of the arguments formControl or a formControlName, but not both at the same time.

Can optionally provide a validationMessages argument to customize a message for different kinds of validation errors.

Can optionally provide a valueAccessor to set a custom value accessors. See ControlValueAccessor.

Can optionally provide a showErrors function to customize when to show validation messages. Reactive Widgets make validation messages visible when the control is INVALID and TOUCHED, this behavior can be customized in the showErrors function.

Example:

Binds a text field.

final form = fb.group({'email': Validators.required});

ReactiveMacosTextField(
  formControlName: 'email',
),

Binds a text field directly with a FormControl.

final form = fb.group({'email': Validators.required});

ReactiveMacosTextField(
  formControl: form.control('email'),
),

Customize validation messages

ReactiveMacosTextField(
  formControlName: 'email',
  validationMessages: {
    ValidationMessage.required: 'The email must not be empty',
    ValidationMessage.email: 'The email must be a valid email',
  }
),

Customize when to show up validation messages.

ReactiveMacosTextField(
  formControlName: 'email',
  showErrors: (control) => control.invalid && control.touched && control.dirty,
),

For documentation about the various parameters, see the MacosTextField class and MacosTextField, the constructor.

Implementation

ReactiveMacosTextField({
  super.key,
  super.formControlName,
  super.formControl,
  super.validationMessages,
  super.valueAccessor,
  super.showErrors,

  ////////////////////////////////////////////////////////////////////////////
  BoxDecoration decoration = _kDefaultRoundedBorderDecoration,
  InputDecoration inputDecoration = const InputDecoration(
    border: InputBorder.none,
    contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0),
    isDense: true,
    isCollapsed: true,
  ),
  BoxDecoration focusedDecoration = _kDefaultFocusedBorderDecoration,
  EdgeInsets padding = const EdgeInsets.all(6.0),
  String? placeholder,
  TextStyle placeholderStyle = const TextStyle(
    fontWeight: FontWeight.w400,
    color: CupertinoColors.placeholderText,
  ),
  TextInputType? keyboardType,
  TextCapitalization textCapitalization = TextCapitalization.none,
  TextInputAction? textInputAction,
  TextStyle? style,
  StrutStyle? strutStyle,
  TextDirection? textDirection,
  TextAlign textAlign = TextAlign.start,
  TextAlignVertical? textAlignVertical,
  bool autofocus = false,
  bool readOnly = false,
  bool? showCursor,
  bool obscureText = false,
  String obscuringCharacter = '•',
  bool autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  bool enableSuggestions = true,
  MaxLengthEnforcement? maxLengthEnforcement,
  int? maxLines = 1,
  int? minLines,
  bool expands = false,
  int? maxLength,
  GestureTapCallback? onTap,
  VoidCallback? onEditingComplete,
  List<TextInputFormatter>? inputFormatters,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Radius cursorRadius = const Radius.circular(2.0),
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  InputCounterWidgetBuilder? buildCounter,
  ScrollPhysics? scrollPhysics,
  ValueChanged<String>? onSubmitted,
  FocusNode? focusNode,
  Iterable<String>? autofillHints,
  MouseCursor? mouseCursor,
  DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  AppPrivateCommandCallback? onAppPrivateCommand,
  String? restorationId,
  ScrollController? scrollController,
  TextSelectionControls? selectionControls,
  ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  Widget? prefix,
  OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
  Widget? suffix,
  OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
  OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never,
}) : super(
        builder: (field) {
          final state = field as _ReactiveMacosTextFieldState<T>;
          final effectiveDecoration = inputDecoration
              .applyDefaults(Theme.of(state.context).inputDecorationTheme);

          state._setFocusNode(focusNode);

          return InputDecorator(
            decoration: effectiveDecoration.copyWith(
              errorText: field.errorText,
              enabled: field.control.enabled,
            ),
            child: MacosTextField(
              controller: state._textController,
              focusNode: state.focusNode,
              decoration: decoration,
              focusedDecoration: focusedDecoration,
              padding: padding,
              placeholder: placeholder,
              placeholderStyle: placeholderStyle,
              prefix: prefix,
              prefixMode: prefixMode,
              suffix: suffix,
              suffixMode: suffixMode,
              clearButtonMode: clearButtonMode,
              keyboardType: keyboardType,
              textInputAction: textInputAction,
              textCapitalization: textCapitalization,
              style: style,
              strutStyle: strutStyle,
              textAlign: textAlign,
              textAlignVertical: textAlignVertical,
              readOnly: readOnly,
              showCursor: showCursor,
              autofocus: autofocus,
              obscuringCharacter: obscuringCharacter,
              obscureText: obscureText,
              autocorrect: autocorrect,
              smartDashesType: smartDashesType,
              smartQuotesType: smartQuotesType,
              enableSuggestions: enableSuggestions,
              maxLines: maxLines,
              minLines: minLines,
              expands: expands,
              maxLength: maxLength,
              maxLengthEnforcement: maxLengthEnforcement,
              onChanged: field.didChange,
              onEditingComplete: onEditingComplete,
              onSubmitted: onSubmitted,
              inputFormatters: inputFormatters,
              enabled: field.control.enabled,
              cursorWidth: cursorWidth,
              cursorHeight: cursorHeight,
              cursorRadius: cursorRadius,
              cursorColor: cursorColor,
              selectionHeightStyle: selectionHeightStyle,
              selectionWidthStyle: selectionWidthStyle,
              keyboardAppearance: keyboardAppearance,
              scrollPadding: scrollPadding,
              dragStartBehavior: dragStartBehavior,
              enableInteractiveSelection: enableInteractiveSelection,
              selectionControls: selectionControls,
              onTap: onTap,
              scrollController: scrollController,
              scrollPhysics: scrollPhysics,
              autofillHints: autofillHints,
              restorationId: restorationId,
            ),
          );
        },
      );