44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
|
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)
|
||
|
],
|
||
|
));
|
||
|
}
|
||
|
}
|