81 lines
2.4 KiB
Dart
81 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:smoke_cess_app/widgets/elevated_card.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';
|
|
import 'package:smoke_cess_app/widgets/timepicker.dart';
|
|
|
|
class SleepForm extends StatefulWidget {
|
|
const SleepForm({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<SleepForm> createState() => _SleepFormState();
|
|
}
|
|
|
|
class _SleepFormState extends State<SleepForm> {
|
|
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
|
MySlider slider = const MySlider('');
|
|
String _textInput = "";
|
|
TimePicker sleepTimePicker = TimePicker(
|
|
const TimeOfDay(hour: 22, minute: 00),
|
|
);
|
|
TimePicker wakeUpTimePicker = TimePicker(
|
|
const TimeOfDay(hour: 8, minute: 00),
|
|
);
|
|
|
|
void submitForm() {
|
|
if (_sleepFormKey.currentState!.validate()) {
|
|
_sleepFormKey.currentState?.save();
|
|
print(_textInput);
|
|
print(slider.getSliderValue());
|
|
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
|
|
_sleepFormKey.currentState?.reset();
|
|
}
|
|
}
|
|
|
|
void onFormFieldSave(String? newValue) => _textInput = newValue!;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Form(
|
|
key: _sleepFormKey,
|
|
child: Stack(
|
|
children: [
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
ElevatedCard(
|
|
child: sleepTimePicker,
|
|
title: 'Einschlafzeit',
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedCard(
|
|
child: wakeUpTimePicker,
|
|
title: 'Aufwachzeit',
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedCard(
|
|
child: slider,
|
|
title: 'Schlafbewertung',
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedCard(
|
|
child: MyTextFormField(
|
|
'Beschreibe deinen Schlaf', onFormFieldSave),
|
|
title: 'Schlafbeschreibung',
|
|
),
|
|
const SizedBox(
|
|
height: 32,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SubmitFormButton(submitForm),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|