From 0d4e7e4a9235581585edde1457c8bb60f53cb173 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Tue, 21 Feb 2023 13:39:06 +0100 Subject: [PATCH] Nice Cards and silder with input --- lib/widgets/sleep_form.dart | 20 +++++--- lib/widgets/slider.dart | 100 ++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index fd4ada5..52eefe8 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -48,32 +48,40 @@ class _SleepFormState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ElevatedCard( - child: sleepTimePicker, title: 'Einschlafzeit', + child: sleepTimePicker, ), const SizedBox(height: 16), ElevatedCard( - child: wakeUpTimePicker, title: 'Aufwachzeit', + child: wakeUpTimePicker, ), const SizedBox(height: 16), ElevatedCard( - child: slider, title: 'Schlafbewertung', + child: slider, ), const SizedBox(height: 16), ElevatedCard( + title: 'Schlafbeschreibung', child: MyTextFormField( 'Beschreibe deinen Schlaf', onFormFieldSave), - title: 'Schlafbeschreibung', ), const SizedBox( - height: 32, + height: 80, ), ], ), ), - SubmitFormButton(submitForm), + Positioned( + bottom: 0, + right: 0, + child: SizedBox( + width: 140, + height: 80, + child: SubmitFormButton(submitForm), + ), + ), ], ), ); diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index 928c3ba..9d896b7 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -4,7 +4,7 @@ double _currentSliderValue = 50; class MySlider extends StatefulWidget { final String _title; - const MySlider(this._title, {super.key}); + const MySlider(this._title, {Key? key}) : super(key: key); @override State createState() => SliderState(); @@ -21,23 +21,22 @@ class SliderState extends State { @override void initState() { super.initState(); - _textFieldController.text = _currentSliderValue.toString(); + _textFieldController.text = _currentSliderValue.toStringAsFixed(0); } @override Widget build(BuildContext context) { - return Column( - children: [ - Text(widget._title), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SliderTheme( - data: SliderThemeData( - thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0), - trackHeight: 2.0, - ), - child: Slider( + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(widget._title), + SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: Slider( value: _currentSliderValue, min: 1, max: 100, @@ -46,49 +45,50 @@ class SliderState extends State { onChanged: (double value) { setState(() { _currentSliderValue = value; - _textFieldController.text = - _currentSliderValue.toString(); + _textFieldController.text = _currentSliderValue.toStringAsFixed(0); _errorText = null; }); - }), - ), - SizedBox(width: 16.0), - SizedBox( - width: 50, - child: TextFormField( - controller: _textFieldController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: 'Enter value', - errorText: _errorText, + }, ), - onChanged: (text) { - if (text.isEmpty) { - _currentSliderValue = 0; + ), + SizedBox(width: 16), + SizedBox( + width: 100, + child: TextFormField( + controller: _textFieldController, + keyboardType: TextInputType.number, + decoration: InputDecoration( + labelText: 'Stimmung', + 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; }); - 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; - }); - }, + }, + ), ), - ), - ], - ), - ], + ], + ), + ], + ), ); } }