Slider constructor

const Slider({
  1. Key? key,
  2. required double value,
  3. double? secondaryTrackValue,
  4. required ValueChanged<double>? onChanged,
  5. ValueChanged<double>? onChangeStart,
  6. ValueChanged<double>? onChangeEnd,
  7. double min = 0.0,
  8. double max = 1.0,
  9. int? divisions,
  10. String? label,
  11. Color? activeColor,
  12. Color? inactiveColor,
  13. Color? secondaryActiveColor,
  14. Color? thumbColor,
  15. MaterialStateProperty<Color?>? overlayColor,
  16. MouseCursor? mouseCursor,
  17. SemanticFormatterCallback? semanticFormatterCallback,
  18. FocusNode? focusNode,
  19. bool autofocus = false,
  20. SliderInteraction? allowedInteraction,
})

Creates a Material Design slider.

The slider itself does not maintain any state. Instead, when the state of the slider changes, the widget calls the onChanged callback. Most widgets that use a slider will listen for the onChanged callback and rebuild the slider with a new value to update the visual appearance of the slider.

  • value determines currently selected value for this slider.
  • onChanged is called while the user is selecting a new value for the slider.
  • onChangeStart is called when the user starts to select a new value for the slider.
  • onChangeEnd is called when the user is done selecting a new value for the slider.

You can override some of the colors with the activeColor and inactiveColor properties, although more fine-grained control of the appearance is achieved using a SliderThemeData.

Implementation

const Slider({
  super.key,
  required this.value,
  this.secondaryTrackValue,
  required this.onChanged,
  this.onChangeStart,
  this.onChangeEnd,
  this.min = 0.0,
  this.max = 1.0,
  this.divisions,
  this.label,
  this.activeColor,
  this.inactiveColor,
  this.secondaryActiveColor,
  this.thumbColor,
  this.overlayColor,
  this.mouseCursor,
  this.semanticFormatterCallback,
  this.focusNode,
  this.autofocus = false,
  this.allowedInteraction,
}) : _sliderType = _SliderType.material,
     assert(min <= max),
     assert(value >= min && value <= max,
       'Value $value is not between minimum $min and maximum $max'),
     assert(secondaryTrackValue == null || (secondaryTrackValue >= min && secondaryTrackValue <= max),
       'SecondaryValue $secondaryTrackValue is not between $min and $max'),
     assert(divisions == null || divisions > 0);