main.dart
import 'package:flutter/material.dart';
void main() => runApp(const FlutterExample());
class FlutterExample extends StatelessWidget {
const FlutterExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(primarySwatch: Colors.blue),
home: const StateExample()
);
}
}
class StateExample extends StatefulWidget {
const StateExample({Key? key}) : super(key: key);
@override
_StateExampleState createState() => _StateExampleState();
}
class _StateExampleState extends State<StateExample> {
double _value = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
title: const Text("Flutter - Slider Label")
),
body: bodyContent()
);
}
bodyContent(){
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Value : ${_value.toInt()}",
style: const TextStyle(
color: Colors.pink,
fontSize: 30
),
),
Slider(
value: _value,
onChanged: (double value){
setState(() {
_value = value;
});
},
min: 1,
max: 100,
divisions: 20,
// show above the slider when the slider is active.
label: "${_value.toInt()}",
)
]
);
}
}
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/06/c8ad7-fluttersliderlabelexample.png)
![](https://fluttertuts.wordpress.com/wp-content/uploads/2021/06/739ed-fluttersliderlabelexample2.png)
More flutter tutorials
- flutter – How to create rounded corners ToggleButtons
- flutter – How to use ToggleButtons onPressed
- flutter – How to show vertical ToggleButtons
- flutter – Checkbox checked color
- flutter – Checkbox onChanged
- flutter – CheckboxListTile left
- flutter – CheckboxListTile subtitle and icon
- flutter – Radio button horizontal
- flutter – Radio button size
- flutter – Radio button onChanged
- flutter – Radio button default selected
- flutter – RangeSlider example
- flutter – RangeSlider labels
- flutter – PageView example
- flutter – PageView disable swipe