Merge branch 'prettier-slider' into 'main'
Prettier slider Closes #28 See merge request Crondung/hsma_cpd!12main
commit
60d8c6653a
|
@ -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() {
|
||||
|
@ -22,7 +22,7 @@ class _MoodFormState extends State<MoodForm> {
|
|||
_moodFormKey.currentState?.save(); //call every onSave Method
|
||||
//TODO Businesslogik aufrufen!
|
||||
print(_textInput);
|
||||
print(slider.getSliderValue());
|
||||
print(slider.sliderValue);
|
||||
_moodFormKey.currentState?.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,9 +29,9 @@ class TimerStartStopPopupState extends State<TimerStartStopPopup> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
child: MySlider(labelText: 'Motivation'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: MySlider(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
MyTextFormField('Beschreibe deinen Motivation', onFormFieldSave),
|
||||
|
|
|
@ -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),
|
||||
|
@ -28,7 +28,7 @@ class _SleepFormState extends State<SleepForm> {
|
|||
_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();
|
||||
}
|
||||
|
|
|
@ -1,90 +1,58 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
double _currentSliderValue = 50;
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class MySlider extends StatefulWidget {
|
||||
final String _labelText;
|
||||
const MySlider({Key? key, String labelText = 'Stimmung'})
|
||||
: _labelText = labelText,
|
||||
super(key: key);
|
||||
double _currentSliderValue = 50;
|
||||
MySlider({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => SliderState();
|
||||
|
||||
double getSliderValue() {
|
||||
return _currentSliderValue;
|
||||
}
|
||||
double get sliderValue => _currentSliderValue;
|
||||
}
|
||||
|
||||
class SliderState extends State<MySlider> {
|
||||
TextEditingController _textFieldController = TextEditingController();
|
||||
String? _errorText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_textFieldController.text = _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: _currentSliderValue,
|
||||
min: 1,
|
||||
value: widget._currentSliderValue,
|
||||
min: 0,
|
||||
max: 100,
|
||||
divisions: 99,
|
||||
label: _currentSliderValue.round().toString(),
|
||||
divisions: 100,
|
||||
label: widget._currentSliderValue.round().toString(),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_currentSliderValue = value;
|
||||
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
|
||||
_errorText = null;
|
||||
widget._currentSliderValue = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
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(() {
|
||||
_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(() {
|
||||
_currentSliderValue = value;
|
||||
_errorText = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_outlined),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
widget._currentSliderValue += 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue