cpd_2022_zi/lib/widgets/slider.dart

52 lines
1.5 KiB
Dart
Raw Normal View History

2023-02-26 14:59:37 +01:00
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
2023-02-26 14:59:37 +01:00
import 'package:smoke_cess_app/providers/input_provider.dart';
2023-02-26 14:59:37 +01:00
class MySlider extends StatelessWidget {
2023-02-26 17:07:38 +01:00
const MySlider({super.key});
@override
Widget build(BuildContext context) {
2023-02-26 17:07:38 +01:00
InputProvider inputModel = context.watch<InputProvider>();
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),
2023-02-26 14:59:37 +01:00
Text('${inputModel.sliderValue.toInt()}',
2023-02-26 11:30:24 +01:00
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: () {
2023-02-26 14:59:37 +01:00
inputModel.sliderValue -= 1;
2023-02-26 11:30:24 +01:00
},
),
2023-02-21 13:39:06 +01:00
Expanded(
child: Slider(
2023-02-26 14:59:37 +01:00
value: inputModel.sliderValue,
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 14:59:37 +01:00
label: '${inputModel.sliderValue.toInt()}',
2023-02-21 00:20:43 +01:00
onChanged: (double value) {
2023-02-26 14:59:37 +01:00
inputModel.sliderValue = value;
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: () {
2023-02-26 14:59:37 +01:00
inputModel.sliderValue += 1;
2023-02-26 11:30:24 +01:00
},
2023-02-21 00:20:43 +01:00
),
2023-02-21 13:39:06 +01:00
],
),
],
),
);
}
}