FormeSlider constructor

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

Implementation

FormeSlider({
  super.key,
  super.name,
  double? 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<double>? decorator,
  required this.min,
  required this.max,
  this.activeColor,
  this.autofocus = false,
  this.divisions,
  this.inactiveColor,
  this.labelRender,
  this.mouseCursor,
  this.onChangeEnd,
  this.onChangeStart,
  this.onChanged,
  this.overlayColor,
  this.secondaryActiveColor,
  this.secondaryTrackValue,
  this.semanticFormatterCallback,
  this.sliderThemeData,
  this.thumbColor,
  this.decoration,
  this.shapeBuilder,
}) : super.allFields(
        initialValue: initialValue ?? min,
        decorator: decorator ??
            (decoration == null
                ? null
                : FormeInputDecorationDecorator(
                    decorationBuilder: (context) => decoration)),
        builder: (baseState) {
          final _FormeSliderState state = baseState as _FormeSliderState;
          final bool readOnly = state.readOnly;

          final Widget slider = ValueListenableBuilder<double?>(
            valueListenable: state.notifier,
            builder: (context, value, child) {
              final String? sliderLabel =
                  labelRender == null ? null : labelRender(state.value);
              SliderThemeData themeData =
                  sliderThemeData ?? SliderTheme.of(state.context);
              if (themeData.thumbShape == null) {
                themeData = themeData.copyWith(
                    thumbShape:
                        shapeBuilder?.call(state.context, state.value) ??
                            CustomSliderThumbCircle(value: state.value));
              }
              return SliderTheme(
                data: themeData,
                child: Slider(
                  secondaryTrackValue: secondaryTrackValue,
                  secondaryActiveColor: secondaryActiveColor,
                  autofocus: autofocus,
                  overlayColor: overlayColor,
                  thumbColor: thumbColor,
                  value: state.value,
                  min: min,
                  max: max,
                  focusNode: state.focusNode,
                  label: sliderLabel,
                  divisions: divisions ?? (max - min).floor(),
                  activeColor: activeColor,
                  inactiveColor: inactiveColor,
                  onChangeStart: (v) {
                    state.focusNode.requestFocus();
                    onChangeStart?.call(v);
                  },
                  onChangeEnd: (v) {
                    state.didChange(v);
                    onChangeEnd?.call(v);
                  },
                  semanticFormatterCallback: semanticFormatterCallback,
                  mouseCursor: mouseCursor,
                  onChanged: readOnly
                      ? null
                      : (double value) {
                          state.updateValue(value);
                          onChanged?.call(value);
                        },
                ),
              );
            },
          );

          return slider;
        },
      );