made widgets reusable, added sleep form
parent
4b2e900bda
commit
704025870b
|
@ -1,10 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:smoke_cess_app/widgets/sleep_form.dart';
|
||||||
|
|
||||||
class SleepPage extends StatelessWidget {
|
class SleepPage extends StatelessWidget {
|
||||||
const SleepPage({super.key});
|
const SleepPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Center(child: Text('Hier wird Schlafqualität abgefragt'));
|
return const Center(child: SleepForm());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MoodForm extends StatefulWidget {
|
||||||
|
|
||||||
class _MoodFormState extends State<MoodForm> {
|
class _MoodFormState extends State<MoodForm> {
|
||||||
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
||||||
MySlider slider = const MySlider();
|
MySlider slider = const MySlider('Bewerte deine Stimmung');
|
||||||
String _textInput = "";
|
String _textInput = "";
|
||||||
|
|
||||||
void submitForm() {
|
void submitForm() {
|
||||||
|
@ -35,7 +35,7 @@ class _MoodFormState extends State<MoodForm> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
slider,
|
slider,
|
||||||
MyTextFormField(onFormFieldSave),
|
MyTextFormField('Beschreibe deine Stimmung', onFormFieldSave),
|
||||||
SubmitFormButton(submitForm)
|
SubmitFormButton(submitForm)
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
|
@ -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<SleepForm> createState() => _SleepFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SleepFormState extends State<SleepForm> {
|
||||||
|
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
||||||
|
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)
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,8 @@ import 'package:flutter/material.dart';
|
||||||
double _currentSliderValue = 50;
|
double _currentSliderValue = 50;
|
||||||
|
|
||||||
class MySlider extends StatefulWidget {
|
class MySlider extends StatefulWidget {
|
||||||
const MySlider({super.key});
|
final String _title;
|
||||||
|
const MySlider(this._title, {super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => SliderState();
|
State<StatefulWidget> createState() => SliderState();
|
||||||
|
@ -18,7 +19,7 @@ class SliderState extends State<MySlider> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
const Text('Bewerte deine Stimmung'),
|
Text(widget._title),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class MyTextFormField extends StatelessWidget {
|
class MyTextFormField extends StatelessWidget {
|
||||||
|
final String _description;
|
||||||
final Function(String?) onSaveAction;
|
final Function(String?) onSaveAction;
|
||||||
const MyTextFormField(
|
const MyTextFormField(
|
||||||
|
this._description,
|
||||||
this.onSaveAction, {
|
this.onSaveAction, {
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -11,7 +13,7 @@ class MyTextFormField extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TextFormField(
|
return TextFormField(
|
||||||
onSaved: onSaveAction,
|
onSaved: onSaveAction,
|
||||||
decoration: const InputDecoration(hintText: 'Beschreibe deine Stimmung?'),
|
decoration: InputDecoration(hintText: _description),
|
||||||
validator: (String? value) =>
|
validator: (String? value) =>
|
||||||
value == null || value.isEmpty ? 'Text eingeben' : null,
|
value == null || value.isEmpty ? 'Text eingeben' : null,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
|
|
Loading…
Reference in New Issue