From 704025870b61f2a6736d68072008b8a3686933ed Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 16 Feb 2023 12:00:02 +0100 Subject: [PATCH 01/11] made widgets reusable, added sleep form --- lib/pages/sleep_page.dart | 3 ++- lib/widgets/mood_form.dart | 4 +-- lib/widgets/sleep_form.dart | 43 +++++++++++++++++++++++++++++++++ lib/widgets/slider.dart | 5 ++-- lib/widgets/text_formfield.dart | 4 ++- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 lib/widgets/sleep_form.dart diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart index 281c580..e736f44 100644 --- a/lib/pages/sleep_page.dart +++ b/lib/pages/sleep_page.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/sleep_form.dart'; class SleepPage extends StatelessWidget { const SleepPage({super.key}); @override Widget build(BuildContext context) { - return const Center(child: Text('Hier wird Schlafqualität abgefragt')); + return const Center(child: SleepForm()); } } diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index fa7d175..23ea2b7 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -12,7 +12,7 @@ class MoodForm extends StatefulWidget { class _MoodFormState extends State { final GlobalKey _moodFormKey = GlobalKey(); - MySlider slider = const MySlider(); + MySlider slider = const MySlider('Bewerte deine Stimmung'); String _textInput = ""; void submitForm() { @@ -35,7 +35,7 @@ class _MoodFormState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ slider, - MyTextFormField(onFormFieldSave), + MyTextFormField('Beschreibe deine Stimmung', onFormFieldSave), SubmitFormButton(submitForm) ], )); diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart new file mode 100644 index 0000000..ae5bfd2 --- /dev/null +++ b/lib/widgets/sleep_form.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/slider.dart'; +import 'package:smoke_cess_app/widgets/submit_form_button.dart'; +import 'package:smoke_cess_app/widgets/text_formfield.dart'; + +class SleepForm extends StatefulWidget { + const SleepForm({super.key}); + + @override + State createState() => _SleepFormState(); +} + +class _SleepFormState extends State { + final GlobalKey _sleepFormKey = GlobalKey(); + MySlider slider = const MySlider('Bewerte deinen Schlaf'); + String _textInput = ""; + + void submitForm() { + if (_sleepFormKey.currentState!.validate()) { + _sleepFormKey.currentState?.save(); //call every onSave Method + //TODO Businesslogik aufrufen! + print(_textInput); + print(slider.getSliderValue()); + _sleepFormKey.currentState?.reset(); + } + } + + void onFormFieldSave(String? newValue) => _textInput = newValue!; + + @override + Widget build(BuildContext context) { + return Form( + key: _sleepFormKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + slider, + MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave), + SubmitFormButton(submitForm) + ], + )); + } +} diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index fb8e063..ba9d78b 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -3,7 +3,8 @@ import 'package:flutter/material.dart'; double _currentSliderValue = 50; class MySlider extends StatefulWidget { - const MySlider({super.key}); + final String _title; + const MySlider(this._title, {super.key}); @override State createState() => SliderState(); @@ -18,7 +19,7 @@ class SliderState extends State { Widget build(BuildContext context) { return Column( children: [ - const Text('Bewerte deine Stimmung'), + Text(widget._title), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ diff --git a/lib/widgets/text_formfield.dart b/lib/widgets/text_formfield.dart index b8a7d02..102a350 100644 --- a/lib/widgets/text_formfield.dart +++ b/lib/widgets/text_formfield.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; class MyTextFormField extends StatelessWidget { + final String _description; final Function(String?) onSaveAction; const MyTextFormField( + this._description, this.onSaveAction, { super.key, }); @@ -11,7 +13,7 @@ class MyTextFormField extends StatelessWidget { Widget build(BuildContext context) { return TextFormField( onSaved: onSaveAction, - decoration: const InputDecoration(hintText: 'Beschreibe deine Stimmung?'), + decoration: InputDecoration(hintText: _description), validator: (String? value) => value == null || value.isEmpty ? 'Text eingeben' : null, keyboardType: TextInputType.multiline, From b67a4f27d0ca2b1380476c8e4727a928884e9ace Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Fri, 17 Feb 2023 11:35:05 +0100 Subject: [PATCH 02/11] wip --- lib/widgets/elevated_card.dart | 19 +++++++++++ lib/widgets/sleep_form.dart | 14 ++++++-- lib/widgets/timepicker.dart | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 lib/widgets/elevated_card.dart create mode 100644 lib/widgets/timepicker.dart diff --git a/lib/widgets/elevated_card.dart b/lib/widgets/elevated_card.dart new file mode 100644 index 0000000..a836219 --- /dev/null +++ b/lib/widgets/elevated_card.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; + +class ElevatedCard extends StatelessWidget { + final Widget? _child; + const ElevatedCard(this._child, {super.key}); + + @override + Widget build(BuildContext context) { + return Center( + child: Card( + child: SizedBox( + width: 300, + height: 100, + child: _child, + ), + ), + ); + } +} diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index ae5bfd2..c56b550 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/elevated_card.dart'; import 'package:smoke_cess_app/widgets/slider.dart'; import 'package:smoke_cess_app/widgets/submit_form_button.dart'; import 'package:smoke_cess_app/widgets/text_formfield.dart'; +import 'package:smoke_cess_app/widgets/timepicker.dart'; class SleepForm extends StatefulWidget { const SleepForm({super.key}); @@ -14,6 +16,10 @@ class _SleepFormState extends State { final GlobalKey _sleepFormKey = GlobalKey(); MySlider slider = const MySlider('Bewerte deinen Schlaf'); String _textInput = ""; + TimePicker sleepTimePicker = + const TimePicker(TimeOfDay(hour: 22, minute: 00)); + TimePicker wakeUpTimePicker = + const TimePicker(TimeOfDay(hour: 8, minute: 00)); void submitForm() { if (_sleepFormKey.currentState!.validate()) { @@ -34,8 +40,12 @@ class _SleepFormState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - slider, - MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave), + TimePicker(TimeOfDay(hour: 22, minute: 00)), + ElevatedCard(sleepTimePicker), + ElevatedCard(wakeUpTimePicker), + ElevatedCard(slider), + ElevatedCard( + MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave)), SubmitFormButton(submitForm) ], )); diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart new file mode 100644 index 0000000..051ee2f --- /dev/null +++ b/lib/widgets/timepicker.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; + +class TimePicker extends StatefulWidget { + final TimeOfDay _initialTime; + const TimePicker(this._initialTime, {super.key}); + + @override + State createState() => _TimePickerState(); +} + +class _TimePickerState extends State { + TimeOfDay time = const TimeOfDay(hour: 12, minute: 0); + + @override + Widget build(BuildContext context) { + time = widget._initialTime; + final hours = time.hour.toString().padLeft(2, '0'); + final minutes = time.minute.toString().padLeft(2, '0'); + + return Center( + child: Column(children: [ + const Text( + 'Das ist die Zeit', + style: TextStyle(fontSize: 18), + ), + const SizedBox(height: 16), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text( + '${time.hour}:${time.minute}', + style: const TextStyle(fontSize: 32), + ), + const SizedBox(width: 16), + ElevatedButton( + onPressed: () async { + //TODO auslagern + TimeOfDay? newTime = await showTimePicker( + context: context, + initialTime: time, + builder: (context, child) { + return MediaQuery( + data: MediaQuery.of(context) + .copyWith(alwaysUse24HourFormat: true), + child: child!, + ); + }, + ); + if (newTime == null) return; + setState(() { + time = newTime; + print('Zeit geändert $newTime, Zeit aktualisiert?: $time'); + }); + }, + child: const Text('Zeit einstellen')) + ]) + ]), + ); + } +} From c9e57b06d6db136fecdde7d8230a951d0045ae37 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 20 Feb 2023 23:23:37 +0100 Subject: [PATCH 03/11] fixed it, but dont know how (: --- lib/pages/sleep_page.dart | 2 +- lib/widgets/sleep_form.dart | 14 +++++++++----- lib/widgets/timepicker.dart | 34 ++++++++++++++++------------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart index e736f44..ebb89d4 100644 --- a/lib/pages/sleep_page.dart +++ b/lib/pages/sleep_page.dart @@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Center(child: SleepForm()); + return Center(child: SleepForm()); } } diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index c56b550..e11dba7 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -16,10 +16,14 @@ class _SleepFormState extends State { final GlobalKey _sleepFormKey = GlobalKey(); MySlider slider = const MySlider('Bewerte deinen Schlaf'); String _textInput = ""; - TimePicker sleepTimePicker = - const TimePicker(TimeOfDay(hour: 22, minute: 00)); - TimePicker wakeUpTimePicker = - const TimePicker(TimeOfDay(hour: 8, minute: 00)); + TimePicker sleepTimePicker = TimePicker( + const TimeOfDay(hour: 22, minute: 00), + descriptionText: 'eingeschlafen um', + ); + TimePicker wakeUpTimePicker = TimePicker( + const TimeOfDay(hour: 8, minute: 00), + descriptionText: 'aufgewacht um', + ); void submitForm() { if (_sleepFormKey.currentState!.validate()) { @@ -27,6 +31,7 @@ class _SleepFormState extends State { //TODO Businesslogik aufrufen! print(_textInput); print(slider.getSliderValue()); + print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); _sleepFormKey.currentState?.reset(); } } @@ -40,7 +45,6 @@ class _SleepFormState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - TimePicker(TimeOfDay(hour: 22, minute: 00)), ElevatedCard(sleepTimePicker), ElevatedCard(wakeUpTimePicker), ElevatedCard(slider), diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index 051ee2f..98f6a54 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -1,33 +1,32 @@ import 'package:flutter/material.dart'; +// ignore: must_be_immutable class TimePicker extends StatefulWidget { - final TimeOfDay _initialTime; - const TimePicker(this._initialTime, {super.key}); + TimeOfDay _initialTime; + final String descriptionText; + TimePicker(this._initialTime, {super.key, required this.descriptionText}); + + TimeOfDay get getCurrentTime => _initialTime; @override - State createState() => _TimePickerState(); + State createState() => TimePickerState(); } -class _TimePickerState extends State { - TimeOfDay time = const TimeOfDay(hour: 12, minute: 0); +class TimePickerState extends State { + TimePickerState(); @override Widget build(BuildContext context) { - time = widget._initialTime; - final hours = time.hour.toString().padLeft(2, '0'); - final minutes = time.minute.toString().padLeft(2, '0'); - return Center( child: Column(children: [ - const Text( - 'Das ist die Zeit', - style: TextStyle(fontSize: 18), + Text( + widget.descriptionText, + style: TextStyle(fontSize: 12), ), - const SizedBox(height: 16), Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - '${time.hour}:${time.minute}', - style: const TextStyle(fontSize: 32), + '${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}', + style: const TextStyle(fontSize: 22), ), const SizedBox(width: 16), ElevatedButton( @@ -35,7 +34,7 @@ class _TimePickerState extends State { //TODO auslagern TimeOfDay? newTime = await showTimePicker( context: context, - initialTime: time, + initialTime: widget._initialTime, builder: (context, child) { return MediaQuery( data: MediaQuery.of(context) @@ -46,8 +45,7 @@ class _TimePickerState extends State { ); if (newTime == null) return; setState(() { - time = newTime; - print('Zeit geändert $newTime, Zeit aktualisiert?: $time'); + widget._initialTime = newTime; }); }, child: const Text('Zeit einstellen')) From af5d7844e3ad25f36ae9f240c927f5d345894365 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 20 Feb 2023 23:28:55 +0100 Subject: [PATCH 04/11] create variables when saving sleep form --- lib/widgets/sleep_form.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index e11dba7..cc39a4d 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -29,9 +29,12 @@ class _SleepFormState extends State { if (_sleepFormKey.currentState!.validate()) { _sleepFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! - print(_textInput); - print(slider.getSliderValue()); - print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); + String sleepComment = _textInput; + int sleepQuality = slider.getSliderValue().round(); + TimeOfDay sleepedAt = sleepTimePicker.getCurrentTime; + TimeOfDay wokeUpAt = wakeUpTimePicker.getCurrentTime; + print( + 'Eingeschlafen um: $sleepedAt, aufgewacht um: $wokeUpAt. \nKommentar zum Schlaf: $sleepComment\nSchlafqualität: $sleepQuality'); _sleepFormKey.currentState?.reset(); } } From adc59a6f42db0d6873bedd6290a3ace0ca34285f Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 20 Feb 2023 23:30:45 +0100 Subject: [PATCH 05/11] use const --- lib/pages/sleep_page.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart index ebb89d4..e736f44 100644 --- a/lib/pages/sleep_page.dart +++ b/lib/pages/sleep_page.dart @@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Center(child: SleepForm()); + return const Center(child: SleepForm()); } } From 5083722d9f7e8f596485e9611b3f064ee9e45a3f Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 20 Feb 2023 23:33:51 +0100 Subject: [PATCH 06/11] use const --- lib/widgets/timepicker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index 98f6a54..6f422ef 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -21,7 +21,7 @@ class TimePickerState extends State { child: Column(children: [ Text( widget.descriptionText, - style: TextStyle(fontSize: 12), + style: const TextStyle(fontSize: 12), ), Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Text( From f5ef084997d4ba115549cf56399de51d57d29aa5 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Mon, 20 Feb 2023 23:59:40 +0100 Subject: [PATCH 07/11] wip --- lib/pages/sleep_page.dart | 2 +- lib/widgets/elevated_card.dart | 36 ++++++++++++++++----- lib/widgets/sleep_form.dart | 59 +++++++++++++++++++++++----------- lib/widgets/slider.dart | 52 ++++++++++++++++++++++++++++-- lib/widgets/timepicker.dart | 57 ++++++++++++++------------------ 5 files changed, 144 insertions(+), 62 deletions(-) diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart index ebb89d4..e736f44 100644 --- a/lib/pages/sleep_page.dart +++ b/lib/pages/sleep_page.dart @@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Center(child: SleepForm()); + return const Center(child: SleepForm()); } } diff --git a/lib/widgets/elevated_card.dart b/lib/widgets/elevated_card.dart index a836219..eba4532 100644 --- a/lib/widgets/elevated_card.dart +++ b/lib/widgets/elevated_card.dart @@ -1,17 +1,37 @@ import 'package:flutter/material.dart'; class ElevatedCard extends StatelessWidget { - final Widget? _child; - const ElevatedCard(this._child, {super.key}); + final Widget child; + final String title; + + const ElevatedCard({ + Key? key, + required this.child, + required this.title, + }) : super(key: key); @override Widget build(BuildContext context) { - return Center( - child: Card( - child: SizedBox( - width: 300, - height: 100, - child: _child, + return Card( + elevation: 4.0, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16.0), + ), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 8.0), + child, + ], ), ), ); diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index e11dba7..4a21672 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -6,7 +6,7 @@ import 'package:smoke_cess_app/widgets/text_formfield.dart'; import 'package:smoke_cess_app/widgets/timepicker.dart'; class SleepForm extends StatefulWidget { - const SleepForm({super.key}); + const SleepForm({Key? key}) : super(key: key); @override State createState() => _SleepFormState(); @@ -14,21 +14,18 @@ class SleepForm extends StatefulWidget { class _SleepFormState extends State { final GlobalKey _sleepFormKey = GlobalKey(); - MySlider slider = const MySlider('Bewerte deinen Schlaf'); + MySlider slider = const MySlider(''); String _textInput = ""; TimePicker sleepTimePicker = TimePicker( const TimeOfDay(hour: 22, minute: 00), - descriptionText: 'eingeschlafen um', ); TimePicker wakeUpTimePicker = TimePicker( const TimeOfDay(hour: 8, minute: 00), - descriptionText: 'aufgewacht um', ); void submitForm() { if (_sleepFormKey.currentState!.validate()) { - _sleepFormKey.currentState?.save(); //call every onSave Method - //TODO Businesslogik aufrufen! + _sleepFormKey.currentState?.save(); print(_textInput); print(slider.getSliderValue()); print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); @@ -41,17 +38,43 @@ class _SleepFormState extends State { @override Widget build(BuildContext context) { return Form( - key: _sleepFormKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ElevatedCard(sleepTimePicker), - ElevatedCard(wakeUpTimePicker), - ElevatedCard(slider), - ElevatedCard( - MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave)), - SubmitFormButton(submitForm) - ], - )); + key: _sleepFormKey, + child: Stack( + children: [ + SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ElevatedCard( + child: sleepTimePicker, + title: 'Einschlafzeit', + ), + const SizedBox(height: 16), + ElevatedCard( + child: wakeUpTimePicker, + title: 'Aufwachzeit', + ), + const SizedBox(height: 16), + ElevatedCard( + child: slider, + title: 'Schlafbewertung', + ), + const SizedBox(height: 16), + ElevatedCard( + child: MyTextFormField( + 'Beschreibe deinen Schlaf', onFormFieldSave), + title: 'Schlafbeschreibung', + ), + const SizedBox( + height: 32, + ), + ], + ), + ), + SubmitFormButton(submitForm), + ], + ), + ); } } diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index ba9d78b..4c6b28b 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -15,6 +15,15 @@ class MySlider extends StatefulWidget { } class SliderState extends State { + TextEditingController _textFieldController = TextEditingController(); + String? _errorText; + + @override + void initState() { + super.initState(); + _textFieldController.text = _currentSliderValue.toString(); + } + @override Widget build(BuildContext context) { return Column( @@ -25,13 +34,50 @@ class SliderState extends State { children: [ Slider( value: _currentSliderValue, + min: 1, max: 100, + divisions: 99, label: _currentSliderValue.round().toString(), - onChanged: (double value) => - {setState((() => _currentSliderValue = value))}), + onChanged: (double value) { + setState(() { + _currentSliderValue = value; + _textFieldController.text = _currentSliderValue.toString(); + _errorText = null; + }); + }), Text(_currentSliderValue.round().toString()) ], - ) + ), + SizedBox(height: 16), + TextFormField( + controller: _textFieldController, + keyboardType: TextInputType.number, + decoration: InputDecoration( + labelText: 'Enter value', + errorText: _errorText, + ), + onChanged: (text) { + if (text.isEmpty) { + _currentSliderValue = 0; + setState(() { + _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; + }); + }, + ), ], ); } diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index 98f6a54..ce93bfb 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -3,8 +3,7 @@ import 'package:flutter/material.dart'; // ignore: must_be_immutable class TimePicker extends StatefulWidget { TimeOfDay _initialTime; - final String descriptionText; - TimePicker(this._initialTime, {super.key, required this.descriptionText}); + TimePicker(this._initialTime, {Key? key}); TimeOfDay get getCurrentTime => _initialTime; @@ -18,38 +17,32 @@ class TimePickerState extends State { @override Widget build(BuildContext context) { return Center( - child: Column(children: [ + child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - widget.descriptionText, - style: TextStyle(fontSize: 12), + '${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}', + style: const TextStyle(fontSize: 22), ), - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - '${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}', - style: const TextStyle(fontSize: 22), - ), - const SizedBox(width: 16), - ElevatedButton( - onPressed: () async { - //TODO auslagern - TimeOfDay? newTime = await showTimePicker( - context: context, - initialTime: widget._initialTime, - builder: (context, child) { - return MediaQuery( - data: MediaQuery.of(context) - .copyWith(alwaysUse24HourFormat: true), - child: child!, - ); - }, - ); - if (newTime == null) return; - setState(() { - widget._initialTime = newTime; - }); - }, - child: const Text('Zeit einstellen')) - ]) + const SizedBox(width: 16), + ElevatedButton( + onPressed: () async { + //TODO auslagern + TimeOfDay? newTime = await showTimePicker( + context: context, + initialTime: widget._initialTime, + builder: (context, child) { + return MediaQuery( + data: MediaQuery.of(context) + .copyWith(alwaysUse24HourFormat: true), + child: child!, + ); + }, + ); + if (newTime == null) return; + setState(() { + widget._initialTime = newTime; + }); + }, + child: const Text('Zeit einstellen')) ]), ); } From af40b847d2651b135352c1724405af5da0ca15d8 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:02:32 +0100 Subject: [PATCH 08/11] wip --- lib/widgets/timepicker.dart | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index 8e61321..ce93bfb 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -43,36 +43,6 @@ class TimePickerState extends State { }); }, child: const Text('Zeit einstellen')) - widget.descriptionText, - style: const TextStyle(fontSize: 12), - ), - Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( - '${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}', - style: const TextStyle(fontSize: 22), - ), - const SizedBox(width: 16), - ElevatedButton( - onPressed: () async { - //TODO auslagern - TimeOfDay? newTime = await showTimePicker( - context: context, - initialTime: widget._initialTime, - builder: (context, child) { - return MediaQuery( - data: MediaQuery.of(context) - .copyWith(alwaysUse24HourFormat: true), - child: child!, - ); - }, - ); - if (newTime == null) return; - setState(() { - widget._initialTime = newTime; - }); - }, - child: const Text('Zeit einstellen')) - ]) ]), ); } From 79c5b8fa4bd125545c29be7f15b52eb9c598f939 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:14:31 +0100 Subject: [PATCH 09/11] neu silder --- lib/widgets/timepicker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index ce93bfb..5e97af5 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; -// ignore: must_be_immutable class TimePicker extends StatefulWidget { TimeOfDay _initialTime; TimePicker(this._initialTime, {Key? key}); @@ -11,6 +10,7 @@ class TimePicker extends StatefulWidget { State createState() => TimePickerState(); } + class TimePickerState extends State { TimePickerState(); From f0e2ce16f2452cb3722887f00601978b451fb66f Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:20:43 +0100 Subject: [PATCH 10/11] wip --- lib/widgets/slider.dart | 90 +++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index 4c6b28b..928c3ba 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -32,52 +32,62 @@ class SliderState extends State { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Slider( - value: _currentSliderValue, - min: 1, - max: 100, - divisions: 99, - label: _currentSliderValue.round().toString(), - onChanged: (double value) { + SliderTheme( + data: SliderThemeData( + thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0), + trackHeight: 2.0, + ), + child: Slider( + value: _currentSliderValue, + min: 1, + max: 100, + divisions: 99, + label: _currentSliderValue.round().toString(), + onChanged: (double value) { + setState(() { + _currentSliderValue = value; + _textFieldController.text = + _currentSliderValue.toString(); + _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; + setState(() { + _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; - _textFieldController.text = _currentSliderValue.toString(); _errorText = null; }); - }), - Text(_currentSliderValue.round().toString()) + }, + ), + ), ], ), - SizedBox(height: 16), - TextFormField( - controller: _textFieldController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: 'Enter value', - errorText: _errorText, - ), - onChanged: (text) { - if (text.isEmpty) { - _currentSliderValue = 0; - setState(() { - _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; - }); - }, - ), ], ); } 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 11/11] 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; - }); - }, + }, + ), ), - ), - ], - ), - ], + ], + ), + ], + ), ); } }