ReactiveSlider constructor

ReactiveSlider({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<num>? formControl,
  4. double min = 0.0,
  5. double max = 1.0,
  6. int? divisions,
  7. ReactiveSliderLabelBuilder? labelBuilder,
  8. Color? activeColor,
  9. Color? inactiveColor,
  10. Color? thumbColor,
  11. SemanticFormatterCallback? semanticFormatterCallback,
  12. bool autofocus = false,
  13. MouseCursor? mouseCursor,
  14. FocusNode? focusNode,
  15. ReactiveFormFieldCallback<num>? onChangeEnd,
  16. ReactiveFormFieldCallback<num>? onChangeStart,
  17. ReactiveFormFieldCallback<num>? onChanged,
  18. double? secondaryTrackValue,
  19. Color? secondaryActiveColor,
  20. MaterialStateProperty<Color?>? overlayColor,
})

Creates an instance os a ReactiveSlider.

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.

The labelBuilder is called each time the FormControl changes its value so you can supply a label to the Slider.

Implementation

ReactiveSlider(
    {super.key,
    super.formControlName,
    super.formControl,
    double min = 0.0,
    double max = 1.0,
    int? divisions,
    ReactiveSliderLabelBuilder? labelBuilder,
    Color? activeColor,
    Color? inactiveColor,
    Color? thumbColor,
    SemanticFormatterCallback? semanticFormatterCallback,
    bool autofocus = false,
    MouseCursor? mouseCursor,
    super.focusNode,
    ReactiveFormFieldCallback<num>? onChangeEnd,
    ReactiveFormFieldCallback<num>? onChangeStart,
    ReactiveFormFieldCallback<num>? onChanged,
    double? secondaryTrackValue,
    Color? secondaryActiveColor,
    MaterialStateProperty<Color?>? overlayColor})
    : super(
        builder: (field) {
          var value = field.value;
          if (value == null) {
            value = min;
          } else if (value < min) {
            value = min;
          } else if (value > max) {
            value = max;
          }

          return Slider(
            value: value,
            min: min,
            max: max,
            divisions: divisions,
            secondaryTrackValue: secondaryTrackValue,
            secondaryActiveColor: secondaryActiveColor,
            overlayColor: overlayColor,
            label: labelBuilder != null
                ? labelBuilder(field.value ?? min)
                : null,
            activeColor: activeColor,
            inactiveColor: inactiveColor,
            thumbColor: thumbColor,
            semanticFormatterCallback: semanticFormatterCallback,
            mouseCursor: mouseCursor,
            autofocus: autofocus,
            focusNode: field.focusNode,
            onChangeEnd: onChangeEnd != null
                ? (_) => onChangeEnd(field.control)
                : null,
            onChangeStart: onChangeStart != null
                ? (_) => onChangeStart(field.control)
                : null,
            onChanged: field.control.enabled
                ? (value) {
                    field.didChange(value);
                    onChanged?.call(field.control);
                  }
                : null,
          );
        },
      );