fix slider bug
parent
b38213a1a4
commit
449230e8d9
|
@ -14,7 +14,7 @@ class MoodForm extends StatefulWidget {
|
|||
|
||||
class _MoodFormState extends State<MoodForm> {
|
||||
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
||||
MySlider slider = const MySlider();
|
||||
MySlider slider = MySlider();
|
||||
String _textInput = "";
|
||||
|
||||
void submitForm() {
|
||||
|
|
|
@ -13,7 +13,7 @@ class TimerStartStopPopup extends StatefulWidget {
|
|||
}
|
||||
|
||||
class TimerStartStopPopupState extends State<TimerStartStopPopup> {
|
||||
final MySlider slider = const MySlider();
|
||||
final MySlider slider = MySlider();
|
||||
|
||||
void submitForm(BuildContext context) {
|
||||
Navigator.of(context).pop();
|
||||
|
@ -29,8 +29,8 @@ class TimerStartStopPopupState extends State<TimerStartStopPopup> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: MySlider(labelText: 'Motivation'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
|
|
@ -14,7 +14,7 @@ class SleepForm extends StatefulWidget {
|
|||
|
||||
class _SleepFormState extends State<SleepForm> {
|
||||
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
||||
MySlider slider = const MySlider();
|
||||
MySlider slider = MySlider();
|
||||
String _textInput = "";
|
||||
TimePicker sleepTimePicker = TimePicker(
|
||||
const TimeOfDay(hour: 22, minute: 00),
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
double _currentSliderValue = 50;
|
||||
|
||||
class MySlider extends StatefulWidget {
|
||||
double _currentSliderValue = 50;
|
||||
final String _labelText;
|
||||
const MySlider({Key? key, String labelText = 'Stimmung'})
|
||||
MySlider({Key? key, String labelText = 'Stimmung'})
|
||||
: _labelText = labelText,
|
||||
super(key: key);
|
||||
|
||||
|
@ -23,7 +22,7 @@ class SliderState extends State<MySlider> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
|
||||
_textFieldController.text = widget._currentSliderValue.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -38,15 +37,16 @@ class SliderState extends State<MySlider> {
|
|||
children: [
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: _currentSliderValue,
|
||||
value: widget._currentSliderValue,
|
||||
min: 1,
|
||||
max: 100,
|
||||
divisions: 99,
|
||||
label: _currentSliderValue.round().toString(),
|
||||
label: widget._currentSliderValue.round().toString(),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_currentSliderValue = value;
|
||||
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
|
||||
widget._currentSliderValue = value;
|
||||
_textFieldController.text =
|
||||
widget._currentSliderValue.toStringAsFixed(0);
|
||||
_errorText = null;
|
||||
});
|
||||
},
|
||||
|
@ -65,7 +65,7 @@ class SliderState extends State<MySlider> {
|
|||
onChanged: (text) {
|
||||
if (text.isEmpty) {
|
||||
setState(() {
|
||||
_currentSliderValue = 1;
|
||||
widget._currentSliderValue = 1;
|
||||
_textFieldController.clear();
|
||||
_errorText = null;
|
||||
});
|
||||
|
@ -80,7 +80,7 @@ class SliderState extends State<MySlider> {
|
|||
return;
|
||||
}
|
||||
setState(() {
|
||||
_currentSliderValue = value;
|
||||
widget._currentSliderValue = value;
|
||||
_errorText = null;
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue