2023-02-16 12:00:02 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-17 11:35:05 +01:00
|
|
|
import 'package:smoke_cess_app/widgets/elevated_card.dart';
|
2023-02-16 12:00:02 +01:00
|
|
|
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';
|
2023-02-17 11:35:05 +01:00
|
|
|
import 'package:smoke_cess_app/widgets/timepicker.dart';
|
2023-02-16 12:00:02 +01:00
|
|
|
|
|
|
|
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 = "";
|
2023-02-20 23:23:37 +01: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',
|
|
|
|
);
|
2023-02-16 12:00:02 +01:00
|
|
|
|
|
|
|
void submitForm() {
|
|
|
|
if (_sleepFormKey.currentState!.validate()) {
|
|
|
|
_sleepFormKey.currentState?.save(); //call every onSave Method
|
|
|
|
//TODO Businesslogik aufrufen!
|
|
|
|
print(_textInput);
|
|
|
|
print(slider.getSliderValue());
|
2023-02-20 23:23:37 +01:00
|
|
|
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
|
2023-02-16 12:00:02 +01:00
|
|
|
_sleepFormKey.currentState?.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onFormFieldSave(String? newValue) => _textInput = newValue!;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Form(
|
|
|
|
key: _sleepFormKey,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2023-02-17 11:35:05 +01:00
|
|
|
ElevatedCard(sleepTimePicker),
|
|
|
|
ElevatedCard(wakeUpTimePicker),
|
|
|
|
ElevatedCard(slider),
|
|
|
|
ElevatedCard(
|
|
|
|
MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave)),
|
2023-02-16 12:00:02 +01:00
|
|
|
SubmitFormButton(submitForm)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|