The Slider widget allows users to select a value from a continuous or discrete range by moving a thumb along a track. It supports both horizontal and vertical orientations.
Basic Horizontal Slider
double volume = 50;
Slider(
value: volume,
min: 0,
max: 100,
onChanged: (value) => setState(() => volume = value),
label: '${volume.round()}%',
)
Slider with Discrete Divisions
Use the divisions property to create discrete steps. This is often used in conjunction with a label to show the current value.
double rating = 3;
Slider(
value: rating,
min: 1,
max: 5,
divisions: 4,
label: rating.round().toString(),
onChanged: (value) => setState(() => rating = value),
)
Vertical Slider
Set the vertical property to true to use a vertical orientation.
Slider(
value: temperature,
min: 0,
max: 100,
vertical: true,
onChanged: (value) => setState(() => temperature = value),
)
double volume = 50;
Slider(
value: volume,
min: 0,
max: 100,
onChanged: (value) => setState(() => volume = value),
label: '${volume.round()}%',
)