cpd_2022_zi/lib/widgets/sleep_form.dart

90 lines
2.7 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-02-17 11:35:05 +01:00
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';
2023-02-17 11:35:05 +01:00
import 'package:smoke_cess_app/widgets/timepicker.dart';
class SleepForm extends StatefulWidget {
2023-02-20 23:59:40 +01:00
const SleepForm({Key? key}) : super(key: key);
@override
State<SleepForm> createState() => _SleepFormState();
}
class _SleepFormState extends State<SleepForm> {
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
2023-02-21 22:33:03 +01:00
MySlider slider = const MySlider();
String _textInput = "";
2023-02-20 23:23:37 +01:00
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(); //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}');
_sleepFormKey.currentState?.reset();
}
}
void onFormFieldSave(String? newValue) => _textInput = newValue!;
@override
Widget build(BuildContext context) {
return Form(
2023-02-20 23:59:40 +01:00
key: _sleepFormKey,
child: Stack(
children: [
SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedCard(
title: 'Einschlafzeit',
2023-02-21 13:39:06 +01:00
child: sleepTimePicker,
2023-02-20 23:59:40 +01:00
),
const SizedBox(height: 16),
ElevatedCard(
title: 'Aufwachzeit',
2023-02-21 13:39:06 +01:00
child: wakeUpTimePicker,
2023-02-20 23:59:40 +01:00
),
const SizedBox(height: 16),
ElevatedCard(
title: 'Schlafbewertung',
2023-02-21 13:39:06 +01:00
child: slider,
2023-02-20 23:59:40 +01:00
),
const SizedBox(height: 16),
ElevatedCard(
2023-02-21 13:39:06 +01:00
title: 'Schlafbeschreibung',
2023-02-20 23:59:40 +01:00
child: MyTextFormField(
'Beschreibe deinen Schlaf', onFormFieldSave),
),
const SizedBox(
2023-02-21 13:39:06 +01:00
height: 80,
2023-02-20 23:59:40 +01:00
),
],
),
),
2023-02-21 13:39:06 +01:00
Positioned(
bottom: 0,
right: 0,
child: SizedBox(
width: 140,
height: 80,
child: SubmitFormButton(submitForm),
),
),
2023-02-20 23:59:40 +01:00
],
),
);
}
}