This app shows a slider from 0 to 100 with steps of 5 (because divisions=20). The current value is shown below the slider and updates as you move the thumb.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
double _sliderValue = 20;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Slider Example')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Slider(
value: _sliderValue,
min: 0,
max: 100,
divisions: 20,
label: _sliderValue.round().toString(),
onChanged: (value) {
setState(() {
_sliderValue = value;
});
},
),
Text('Value: ${_sliderValue.toStringAsFixed(1)}'),
],
),
),
),
);
}
}