ReactiveTouchSpin<T> constructor

ReactiveTouchSpin<T>({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<T>? formControl,
  4. Map<String, ValidationMessageFunction>? validationMessages,
  5. ControlValueAccessor<T, num>? valueAccessor,
  6. ShowErrorsFunction? showErrors,
  7. InputDecoration? decoration,
  8. num min = 1.0,
  9. num max = 9999999.0,
  10. num step = 1.0,
  11. double iconSize = 24.0,
  12. NumberFormat? displayFormat,
  13. Icon subtractIcon = const Icon(Icons.remove),
  14. Icon addIcon = const Icon(Icons.add),
  15. EdgeInsets iconPadding = const EdgeInsets.all(4.0),
  16. TextStyle textStyle = const TextStyle(fontSize: 24),
  17. Color? iconActiveColor,
  18. Color? iconDisabledColor,
})

Creates a ReactiveTouchSpin that contains a TouchSpin.

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});

ReactiveTouchSpin(
  formControlName: 'email',
),

Binds a text field directly with a FormControl.

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

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

Customize validation messages

ReactiveTouchSpin(
  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.

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

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

Implementation

ReactiveTouchSpin({
  Key? key,
  String? formControlName,
  FormControl<T>? formControl,
  Map<String, ValidationMessageFunction>? validationMessages,
  ControlValueAccessor<T, num>? valueAccessor,
  ShowErrorsFunction? showErrors,

  ////////////////////////////////////////////////////////////////////////////
  InputDecoration? decoration,
  num min = 1.0,
  num max = 9999999.0,
  num step = 1.0,
  double iconSize = 24.0,
  NumberFormat? displayFormat,
  Icon subtractIcon = const Icon(Icons.remove),
  Icon addIcon = const Icon(Icons.add),
  EdgeInsets iconPadding = const EdgeInsets.all(4.0),
  TextStyle textStyle = const TextStyle(fontSize: 24),
  Color? iconActiveColor,
  Color? iconDisabledColor,
}) : super(
        key: key,
        formControl: formControl,
        formControlName: formControlName,
        valueAccessor: valueAccessor,
        validationMessages: validationMessages,
        showErrors: showErrors,
        builder: (field) {
          final InputDecoration effectiveDecoration = (decoration ??
                  const InputDecoration())
              .applyDefaults(Theme.of(field.context).inputDecorationTheme);

          return Listener(
            onPointerDown: (_) {
              if (field.control.enabled) {
                field.control.markAsTouched();
              }
            },
            child: InputDecorator(
              decoration: effectiveDecoration.copyWith(
                errorText: field.errorText,
                enabled: field.control.enabled,
              ),
              child: TouchSpin(
                value: field.value ?? min,
                onChanged: (value) {
                  if (field.value != value) {
                    field.didChange(value);
                  }
                },
                min: min,
                max: max,
                step: step,
                iconSize: iconSize,
                displayFormat: displayFormat,
                subtractIcon: subtractIcon,
                addIcon: addIcon,
                iconPadding: iconPadding,
                textStyle: textStyle,
                iconActiveColor: iconActiveColor,
                iconDisabledColor: iconDisabledColor,
                enabled: field.control.enabled,
              ),
            ),
          );
        },
      );