|
6 | 6 |
|
7 | 7 | import 'package:flutter/material.dart';
|
8 | 8 |
|
9 |
| -void main() => runApp(const MyApp()); |
| 9 | +void main() => runApp(const SliderApp()); |
10 | 10 |
|
11 |
| -class MyApp extends StatelessWidget { |
12 |
| - const MyApp({super.key}); |
13 |
| - |
14 |
| - static const String _title = 'Flutter Code Sample'; |
| 11 | +class SliderApp extends StatelessWidget { |
| 12 | + const SliderApp({super.key}); |
15 | 13 |
|
16 | 14 | @override
|
17 | 15 | Widget build(BuildContext context) {
|
18 | 16 | return MaterialApp(
|
19 |
| - title: _title, |
20 |
| - home: Scaffold( |
21 |
| - appBar: AppBar(title: const Text(_title)), |
22 |
| - body: const MyStatefulWidget(), |
| 17 | + theme: ThemeData( |
| 18 | + colorSchemeSeed: const Color(0xff6750a4), |
| 19 | + useMaterial3: true, |
23 | 20 | ),
|
| 21 | + home: const SliderExample(), |
24 | 22 | );
|
25 | 23 | }
|
26 | 24 | }
|
27 | 25 |
|
28 |
| -class MyStatefulWidget extends StatefulWidget { |
29 |
| - const MyStatefulWidget({super.key}); |
| 26 | +class SliderExample extends StatefulWidget { |
| 27 | + const SliderExample({super.key}); |
30 | 28 |
|
31 | 29 | @override
|
32 |
| - State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); |
| 30 | + State<SliderExample> createState() => _SliderExampleState(); |
33 | 31 | }
|
34 | 32 |
|
35 |
| -class _MyStatefulWidgetState extends State<MyStatefulWidget> { |
36 |
| - double _currentSliderPrimaryValue = 0.2; |
37 |
| - double _currentSliderSecondaryValue = 0.5; |
| 33 | +class _SliderExampleState extends State<SliderExample> { |
| 34 | + double _currentSliderValue = 20; |
38 | 35 |
|
39 | 36 | @override
|
40 | 37 | Widget build(BuildContext context) {
|
41 |
| - return Column( |
42 |
| - mainAxisAlignment: MainAxisAlignment.center, |
43 |
| - children: <Widget>[ |
44 |
| - Slider( |
45 |
| - value: _currentSliderPrimaryValue, |
46 |
| - secondaryTrackValue: _currentSliderSecondaryValue, |
47 |
| - label: _currentSliderPrimaryValue.round().toString(), |
48 |
| - onChanged: (double value) { |
49 |
| - setState(() { |
50 |
| - _currentSliderPrimaryValue = value; |
51 |
| - }); |
52 |
| - }, |
53 |
| - ), |
54 |
| - Slider( |
55 |
| - value: _currentSliderSecondaryValue, |
56 |
| - label: _currentSliderSecondaryValue.round().toString(), |
57 |
| - onChanged: (double value) { |
58 |
| - setState(() { |
59 |
| - _currentSliderSecondaryValue = value; |
60 |
| - }); |
61 |
| - }, |
62 |
| - ), |
63 |
| - ], |
| 38 | + return Scaffold( |
| 39 | + appBar: AppBar(title: const Text('Slider')), |
| 40 | + body: Slider( |
| 41 | + value: _currentSliderValue, |
| 42 | + max: 100, |
| 43 | + divisions: 5, |
| 44 | + label: _currentSliderValue.round().toString(), |
| 45 | + onChanged: (double value) { |
| 46 | + setState(() { |
| 47 | + _currentSliderValue = value; |
| 48 | + }); |
| 49 | + }, |
| 50 | + ), |
64 | 51 | );
|
65 | 52 | }
|
66 | 53 | }
|
0 commit comments