FormeRangeSlider constructor

FormeRangeSlider({
  1. Key? key,
  2. String? name,
  3. RangeValues? initialValue,
  4. FormeAsyncValidator<RangeValues>? asyncValidator,
  5. Duration? asyncValidatorDebounce,
  6. AutovalidateMode? autovalidateMode,
  7. bool enabled = true,
  8. FocusNode? focusNode,
  9. FormeFieldInitialized<RangeValues>? onInitialized,
  10. FormeFieldSetter<RangeValues>? onSaved,
  11. FormeFieldStatusChanged<RangeValues>? onStatusChanged,
  12. int? order,
  13. bool quietlyValidate = false,
  14. bool readOnly = false,
  15. bool requestFocusOnUserInteraction = true,
  16. FormeFieldValidationFilter<RangeValues>? validationFilter,
  17. FormeValidator<RangeValues>? validator,
  18. FormeFieldDecorator<RangeValues>? decorator,
  19. required double min,
  20. required double max,
  21. Color? activeColor,
  22. InputDecoration? decoration,
  23. int? divisions,
  24. Color? inactiveColor,
  25. ValueChanged<RangeValues>? onChangeEnd,
  26. ValueChanged<RangeValues>? onChangeStart,
  27. ValueChanged<RangeValues>? onChanged,
  28. FormRangeLabelRender? rangeLabelRender,
  29. SemanticFormatterCallback? semanticFormatterCallback,
  30. SliderThemeData? sliderThemeData,
  31. RangeSliderThumbShapeBuilder? shapeBuilder,
})

Implementation

FormeRangeSlider({
  super.key,
  super.name,
  RangeValues? initialValue,
  super.asyncValidator,
  super.asyncValidatorDebounce,
  super.autovalidateMode,
  super.enabled = true,
  super.focusNode,
  super.onInitialized,
  super.onSaved,
  super.onStatusChanged,
  super.order,
  super.quietlyValidate = false,
  super.readOnly = false,
  super.requestFocusOnUserInteraction = true,
  super.validationFilter,
  super.validator,
  FormeFieldDecorator<RangeValues>? decorator,
  required this.min,
  required this.max,
  this.activeColor,
  this.decoration,
  this.divisions,
  this.inactiveColor,
  this.onChangeEnd,
  this.onChangeStart,
  this.onChanged,
  this.rangeLabelRender,
  this.semanticFormatterCallback,
  this.sliderThemeData,
  this.shapeBuilder,
}) : super.allFields(
          decorator: decorator ??
              (decoration == null
                  ? null
                  : FormeInputDecorationDecorator(
                      decorationBuilder: (context) => decoration)),
          initialValue: initialValue ?? RangeValues(min, max),
          builder: (baseState) {
            final _FormeRangeSliderState state =
                baseState as _FormeRangeSliderState;
            final bool readOnly = state.readOnly;

            final Widget slider = ValueListenableBuilder(
                valueListenable: state.notifier,
                builder: (context, _, __) {
                  RangeLabels? sliderLabels;

                  if (rangeLabelRender != null) {
                    final String start =
                        rangeLabelRender.startRender(state.value.start);
                    final String end =
                        rangeLabelRender.endRender(state.value.end);
                    sliderLabels = RangeLabels(start, end);
                  }

                  SliderThemeData themeData =
                      sliderThemeData ?? SliderTheme.of(state.context);
                  if (themeData.thumbShape == null) {
                    themeData = themeData.copyWith(
                        rangeThumbShape: shapeBuilder?.call(
                                state.context, state.value) ??
                            CustomRangeSliderThumbCircle(value: state.value));
                  }
                  return SliderTheme(
                    data: themeData,
                    child: RangeSlider(
                      values: state.value,
                      min: min,
                      max: max,
                      divisions: divisions ?? (max - min).floor(),
                      labels: sliderLabels,
                      activeColor: activeColor,
                      inactiveColor: inactiveColor,
                      onChangeStart: (v) {
                        state.focusNode.requestFocus();
                        onChangeStart?.call(v);
                      },
                      onChangeEnd: (v) {
                        state.didChange(v);
                        onChangeEnd?.call(v);
                      },
                      semanticFormatterCallback: semanticFormatterCallback,
                      onChanged: readOnly
                          ? null
                          : (RangeValues values) {
                              state.updateValue(values);
                              onChanged?.call(values);
                            },
                    ),
                  );
                });

            return Focus(
              focusNode: state.focusNode,
              child: slider,
            );
          });