Skip to content

Commit 02b9e75

Browse files
authored
Create slider.dart
1 parent cd22ce3 commit 02b9e75

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

slider.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class MyApp extends StatelessWidget {
2+
const MyApp({Key? key}) : super(key: key);
3+
4+
static const String _title = 'Flutter Code Sample';
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return MaterialApp(
9+
title: _title,
10+
home: Scaffold(
11+
appBar: AppBar(title: const Text(_title)),
12+
body: const MyStatefulWidget(),
13+
),
14+
);
15+
}
16+
}
17+
18+
/// This is the stateful widget that the main application instantiates.
19+
class MyStatefulWidget extends StatefulWidget {
20+
const MyStatefulWidget({Key? key}) : super(key: key);
21+
22+
@override
23+
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
24+
}
25+
26+
/// This is the private State class that goes with MyStatefulWidget.
27+
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
28+
double _currentSliderValue = 20;
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return Slider(
33+
value: _currentSliderValue,
34+
min: 0,
35+
max: 100,
36+
divisions: 5,
37+
label: _currentSliderValue.round().toString(),
38+
onChanged: (double value) {
39+
setState(() {
40+
_currentSliderValue = value;
41+
});
42+
},
43+
);
44+
}
45+
}

0 commit comments

Comments
 (0)