cpd_2022_zi/lib/widgets/slider.dart

64 lines
1.8 KiB
Dart

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