diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index 78c3e43..6447a0d 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -22,7 +22,7 @@ class _MoodFormState extends State { _moodFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! print(_textInput); - print(slider.getSliderValue()); + print(slider.sliderValue); _moodFormKey.currentState?.reset(); } } diff --git a/lib/widgets/popup_for_start_and_stop.dart b/lib/widgets/popup_for_start_and_stop.dart index 84f5383..b8ed90a 100644 --- a/lib/widgets/popup_for_start_and_stop.dart +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -31,7 +31,7 @@ class TimerStartStopPopupState extends State { children: [ Padding( padding: const EdgeInsets.only(top: 8), - child: MySlider(labelText: 'Motivation'), + child: MySlider(), ), const SizedBox(height: 16), MyTextFormField('Beschreibe deinen Motivation', onFormFieldSave), diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 5f8b9bd..ba1259c 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -28,7 +28,7 @@ class _SleepFormState extends State { _sleepFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! print(_textInput); - print(slider.getSliderValue()); + print(slider.sliderValue); print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); _sleepFormKey.currentState?.reset(); } diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index 0102014..b642916 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -1,90 +1,58 @@ import 'package:flutter/material.dart'; +// ignore: must_be_immutable class MySlider extends StatefulWidget { double _currentSliderValue = 50; - final String _labelText; - MySlider({Key? key, String labelText = 'Stimmung'}) - : _labelText = labelText, - super(key: key); + MySlider({Key? key}) : super(key: key); @override State createState() => SliderState(); - double getSliderValue() { - return _currentSliderValue; - } + double get sliderValue => _currentSliderValue; } class SliderState extends State { - TextEditingController _textFieldController = TextEditingController(); - String? _errorText; - - @override - void initState() { - super.initState(); - _textFieldController.text = widget._currentSliderValue.toStringAsFixed(0); - } - @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox(height: 16), + 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: 1, + min: 0, max: 100, - divisions: 99, + divisions: 100, label: widget._currentSliderValue.round().toString(), onChanged: (double value) { setState(() { widget._currentSliderValue = value; - _textFieldController.text = - widget._currentSliderValue.toStringAsFixed(0); - _errorText = null; }); }, ), ), - SizedBox(width: 16), - SizedBox( - width: 100, - child: TextFormField( - controller: _textFieldController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: widget._labelText, - errorText: _errorText, - ), - onChanged: (text) { - if (text.isEmpty) { - setState(() { - widget._currentSliderValue = 1; - _textFieldController.clear(); - _errorText = null; - }); - return; - } - final value = double.tryParse(text); - if (value == null || value < 1 || value > 100) { - setState(() { - _textFieldController.clear(); - _errorText = 'Please enter a value between 1 and 100.'; - }); - return; - } - setState(() { - widget._currentSliderValue = value; - _errorText = null; - }); - }, - ), + IconButton( + icon: const Icon(Icons.add_outlined), + onPressed: () { + setState(() { + widget._currentSliderValue += 1; + }); + }, ), ], ),