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 MoodForm extends StatefulWidget { const MoodForm({super.key}); @override State createState() => _MoodFormState(); } class _MoodFormState extends State { final GlobalKey _moodFormKey = GlobalKey(); MySlider slider = const MySlider('Bewerte deine Stimmung'); String _textInput = ""; void submitForm() { if (_moodFormKey.currentState!.validate()) { _moodFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! print(_textInput); print(slider.getSliderValue()); _moodFormKey.currentState?.reset(); } } void onFormFieldSave(String? newValue) => _textInput = newValue!; @override Widget build(BuildContext context) { return Form( key: _moodFormKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ slider, MyTextFormField('Beschreibe deine Stimmung', onFormFieldSave), SubmitFormButton(submitForm) ], )); } }