cpd_2022_zi/lib/widgets/slider.dart

52 lines
1.5 KiB
Dart

import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
class MySlider extends StatelessWidget {
MySlider({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>();
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 16),
Text('${inputModel.sliderValue.toInt()}',
style: const TextStyle(fontSize: 22)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: const Icon(Icons.remove_outlined),
onPressed: () {
inputModel.sliderValue -= 1;
},
),
Expanded(
child: Slider(
value: inputModel.sliderValue,
min: 0,
max: 100,
divisions: 100,
label: '${inputModel.sliderValue.toInt()}',
onChanged: (double value) {
inputModel.sliderValue = value;
},
),
),
IconButton(
icon: const Icon(Icons.add_outlined),
onPressed: () {
inputModel.sliderValue += 1;
},
),
],
),
],
),
);
}
}