cpd_2022_zi/lib/widgets/slider.dart

64 lines
1.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-02-26 11:30:24 +01:00
// ignore: must_be_immutable
class MySlider extends StatefulWidget {
2023-02-26 10:44:16 +01:00
double _currentSliderValue = 50;
2023-02-26 11:30:24 +01:00
MySlider({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => SliderState();
2023-02-15 23:02:29 +01:00
2023-02-26 11:30:24 +01:00
double get sliderValue => _currentSliderValue;
}
class SliderState extends State<MySlider> {
@override
Widget build(BuildContext context) {
2023-02-21 13:39:06 +01:00
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2023-02-26 11:30:24 +01:00
const SizedBox(height: 16),
Text('${widget._currentSliderValue.toInt()}',
style: const TextStyle(fontSize: 22)),
2023-02-21 13:39:06 +01:00
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
2023-02-26 11:30:24 +01:00
IconButton(
icon: const Icon(Icons.remove_outlined),
onPressed: () {
setState(() {
widget._currentSliderValue -= 1;
});
},
),
2023-02-21 13:39:06 +01:00
Expanded(
child: Slider(
2023-02-26 10:44:16 +01:00
value: widget._currentSliderValue,
2023-02-26 11:30:24 +01:00
min: 0,
2023-02-21 00:20:43 +01:00
max: 100,
2023-02-26 11:30:24 +01:00
divisions: 100,
2023-02-26 10:44:16 +01:00
label: widget._currentSliderValue.round().toString(),
2023-02-21 00:20:43 +01:00
onChanged: (double value) {
setState(() {
2023-02-26 10:44:16 +01:00
widget._currentSliderValue = value;
2023-02-21 00:20:43 +01:00
});
2023-02-21 13:39:06 +01:00
},
2023-02-21 00:20:43 +01:00
),
2023-02-21 13:39:06 +01:00
),
2023-02-26 11:30:24 +01:00
IconButton(
icon: const Icon(Icons.add_outlined),
onPressed: () {
setState(() {
widget._currentSliderValue += 1;
});
},
2023-02-21 00:20:43 +01:00
),
2023-02-21 13:39:06 +01:00
],
),
],
),
);
}
}