fixed it, but dont know how (:

main
Julian Gegner 2023-02-20 23:23:37 +01:00
parent b67a4f27d0
commit c9e57b06d6
3 changed files with 26 additions and 24 deletions

View File

@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const Center(child: SleepForm());
return Center(child: SleepForm());
}
}

View File

@ -16,10 +16,14 @@ class _SleepFormState extends State<SleepForm> {
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
MySlider slider = const MySlider('Bewerte deinen Schlaf');
String _textInput = "";
TimePicker sleepTimePicker =
const TimePicker(TimeOfDay(hour: 22, minute: 00));
TimePicker wakeUpTimePicker =
const TimePicker(TimeOfDay(hour: 8, minute: 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',
);
void submitForm() {
if (_sleepFormKey.currentState!.validate()) {
@ -27,6 +31,7 @@ class _SleepFormState extends State<SleepForm> {
//TODO Businesslogik aufrufen!
print(_textInput);
print(slider.getSliderValue());
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
_sleepFormKey.currentState?.reset();
}
}
@ -40,7 +45,6 @@ class _SleepFormState extends State<SleepForm> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TimePicker(TimeOfDay(hour: 22, minute: 00)),
ElevatedCard(sleepTimePicker),
ElevatedCard(wakeUpTimePicker),
ElevatedCard(slider),

View File

@ -1,33 +1,32 @@
import 'package:flutter/material.dart';
// ignore: must_be_immutable
class TimePicker extends StatefulWidget {
final TimeOfDay _initialTime;
const TimePicker(this._initialTime, {super.key});
TimeOfDay _initialTime;
final String descriptionText;
TimePicker(this._initialTime, {super.key, required this.descriptionText});
TimeOfDay get getCurrentTime => _initialTime;
@override
State<StatefulWidget> createState() => _TimePickerState();
State<StatefulWidget> createState() => TimePickerState();
}
class _TimePickerState extends State<TimePicker> {
TimeOfDay time = const TimeOfDay(hour: 12, minute: 0);
class TimePickerState extends State<TimePicker> {
TimePickerState();
@override
Widget build(BuildContext context) {
time = widget._initialTime;
final hours = time.hour.toString().padLeft(2, '0');
final minutes = time.minute.toString().padLeft(2, '0');
return Center(
child: Column(children: [
const Text(
'Das ist die Zeit',
style: TextStyle(fontSize: 18),
Text(
widget.descriptionText,
style: TextStyle(fontSize: 12),
),
const SizedBox(height: 16),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
'${time.hour}:${time.minute}',
style: const TextStyle(fontSize: 32),
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 22),
),
const SizedBox(width: 16),
ElevatedButton(
@ -35,7 +34,7 @@ class _TimePickerState extends State<TimePicker> {
//TODO auslagern
TimeOfDay? newTime = await showTimePicker(
context: context,
initialTime: time,
initialTime: widget._initialTime,
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context)
@ -46,8 +45,7 @@ class _TimePickerState extends State<TimePicker> {
);
if (newTime == null) return;
setState(() {
time = newTime;
print('Zeit geändert $newTime, Zeit aktualisiert?: $time');
widget._initialTime = newTime;
});
},
child: const Text('Zeit einstellen'))