ReactiveCapacityIndicator<T> constructor

ReactiveCapacityIndicator<T>({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<T>? formControl,
  4. Map<String, ValidationMessageFunction>? validationMessages,
  5. ControlValueAccessor<T, double>? valueAccessor,
  6. ShowErrorsFunction<T>? showErrors,
  7. InputDecoration decoration = const InputDecoration(border: InputBorder.none, contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0), isDense: true, isCollapsed: true),
  8. bool discrete = false,
  9. int splits = 10,
  10. Color color = CupertinoColors.systemGreen,
  11. Color borderColor = CupertinoColors.tertiaryLabel,
  12. Color backgroundColor = CupertinoColors.tertiarySystemGroupedBackground,
  13. String? semanticLabel,
})

Creates a ReactiveCapacityIndicator that contains a CapacityIndicator.

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

ReactiveCapacityIndicator(
  formControlName: 'email',
),

Binds a text field directly with a FormControl.

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

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

Customize validation messages

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

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

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

Implementation

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

  ////////////////////////////////////////////////////////////////////////////
  InputDecoration decoration = const InputDecoration(
    border: InputBorder.none,
    contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0),
    isDense: true,
    isCollapsed: true,
  ),
  bool discrete = false,
  int splits = 10,
  Color color = CupertinoColors.systemGreen,
  Color borderColor = CupertinoColors.tertiaryLabel,
  Color backgroundColor = CupertinoColors.tertiarySystemGroupedBackground,
  String? semanticLabel,
}) : super(
        builder: (field) {
          final InputDecoration effectiveDecoration = decoration
              .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: CapacityIndicator(
                value: field.value ?? 0,
                onChanged: field.didChange,
                discrete: discrete,
                splits: splits,
                color: color,
                borderColor: borderColor,
                backgroundColor: backgroundColor,
                semanticLabel: semanticLabel,
              ),
            ),
          );
        },
      );