Slider
A slider changes one value along a bounded track. Use it for adjustments people can judge as they move, such as sound level.
Set the volume
#Move the thumb and watch the volume readout change in five-point steps.
components/slider/appliance/set_volume.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class SetVolume extends StatefulWidget {
const SetVolume({super.key});
@override
State<SetVolume> createState() => _SetVolumeState();
}
class _SetVolumeState extends State<SetVolume> {
double volume = 40;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceSlider(
value: volume,
max: 100,
divisions: 20,
semanticLabel: 'Volume',
valueText: (v) => '${v.round()}%',
onChanged: (next) => setState(() => volume = next),
),
const SizedBox(height: 12),
Text('Volume ${volume.round()}%'),
],
),
);
}
Parameters
ApplianceSlider API ↗value- Current volume on the track.
max- Highest volume the thumb can reach.
divisions- Number of equal intervals on the track.
semanticLabel- Names the volume control.
valueText- Announces the volume as a percentage.
onChanged- Receives the new volume.
Shared behaviour
- Keyboard and focus. Focus the slider and use the arrows to adjust the volume. Try the same keys again in RTL.
- Screen readers. Read the control’s volume label and value, then the percentage printed beside the example.
- Direction and type. At 200% the number grows with the text. Switch direction to see where the low end of the track sits.