Start native apps faster with the Composables CLI ->
Class

SliderState

Class that holds information about Slider's active range.

Source set: Common
class SliderState
@RememberInComposition
constructor(
    value: Float = 0f,
    @IntRange(from = 0) val steps: Int = 0,
    var onValueChangeFinished: (() -> Unit)? = null,
    val valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
) : DraggableState

Class that holds information about Slider's active range.

Parameters

value Float that indicates the initial position of the thumb. If outside of valueRange provided, value will be coerced to this range.
steps if positive, specifies the amount of discrete allowable values between the endpoints of valueRange. For example, a range from 0 to 10 with 4 steps allows 4 values evenly distributed between 0 and 10 (i.e., 2, 4, 6, 8). If steps is 0, the slider will behave continuously and allow any value from the range. Must not be negative.
onValueChangeFinished lambda to be invoked when value change has ended. This callback shouldn't be used to update the slider values (use onValueChange for that), but rather to know when the user has completed selecting a new value by ending a drag or a click.
valueRange range of values that Slider values can take. value will be coerced to this range.

Properties

value

Source set: Common
var value: Float

Float that indicates the value that the thumb currently is in respect to the track.

onValueChange

Source set: Common
var onValueChange: ((Float) -> Unit)?

Callback in which value should be updated.

shouldAutoSnap

Source set: Common
var shouldAutoSnap: Boolean

Controls the auto-snapping mechanism for slider steps.

When true (default), any updates to value will automatically snap to the nearest tick fraction based on the number of steps.

Disabling auto-snapping (false) allows value to be set to any continuous value between valueRange without snapping. This is particularly useful for programmatic animations, smooth transitions, or custom drag gestures where discrete step snapping is temporarily or permanently undesired.

Since this is defined on the state, it can be dynamically toggled during gestures or animations without triggering a full layout recomposition.

isVertical

Source set: Common
val isVertical: Boolean

Whether the slider is vertical.

coercedValueAsFraction

Source set: Common
val coercedValueAsFraction: Float

The fraction of the track that the thumb currently occupies.

The value is coerced (clamped) to the bounds of valueRange before calculating its fractional position (from 0f to 1f) on the track.

isDragging

Source set: Common
var isDragging

Indicates whether the slider is currently being dragged.

This is set to true when a drag gesture starts (either via user touch interaction or programmatically via drag) and set back to false when the gesture completes or is cancelled.

Companion Object

Methods

Source set: Common
fun Saver(
            steps: Int,
            valueRange: ClosedFloatingPointRange<Float>,
            onValueChangeFinished: (() -> Unit)?,
        ): Saver<SliderState, *>

The default Saver implementation for SliderState.

Parameters

steps if positive, specifies the amount of discrete allowable values between the endpoints of valueRange.
valueRange range of values that Slider values can take. value will be coerced to this range.
onValueChangeFinished lambda to be invoked when value change has ended.

Deprecated

Maintained for binary compatibility.

Source set: Common
fun Saver(
            onValueChangeFinished: (() -> Unit)?,
            valueRange: ClosedFloatingPointRange<Float>,
        ): Saver<SliderState, *>

Last updated: