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,