fixed it, but dont know how (:
parent
b67a4f27d0
commit
c9e57b06d6
|
@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Center(child: SleepForm());
|
return Center(child: SleepForm());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,14 @@ class _SleepFormState extends State<SleepForm> {
|
||||||
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
||||||
MySlider slider = const MySlider('Bewerte deinen Schlaf');
|
MySlider slider = const MySlider('Bewerte deinen Schlaf');
|
||||||
String _textInput = "";
|
String _textInput = "";
|
||||||
TimePicker sleepTimePicker =
|
TimePicker sleepTimePicker = TimePicker(
|
||||||
const TimePicker(TimeOfDay(hour: 22, minute: 00));
|
const TimeOfDay(hour: 22, minute: 00),
|
||||||
TimePicker wakeUpTimePicker =
|
descriptionText: 'eingeschlafen um',
|
||||||
const TimePicker(TimeOfDay(hour: 8, minute: 00));
|
);
|
||||||
|
TimePicker wakeUpTimePicker = TimePicker(
|
||||||
|
const TimeOfDay(hour: 8, minute: 00),
|
||||||
|
descriptionText: 'aufgewacht um',
|
||||||
|
);
|
||||||
|
|
||||||
void submitForm() {
|
void submitForm() {
|
||||||
if (_sleepFormKey.currentState!.validate()) {
|
if (_sleepFormKey.currentState!.validate()) {
|
||||||
|
@ -27,6 +31,7 @@ class _SleepFormState extends State<SleepForm> {
|
||||||
//TODO Businesslogik aufrufen!
|
//TODO Businesslogik aufrufen!
|
||||||
print(_textInput);
|
print(_textInput);
|
||||||
print(slider.getSliderValue());
|
print(slider.getSliderValue());
|
||||||
|
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
|
||||||
_sleepFormKey.currentState?.reset();
|
_sleepFormKey.currentState?.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +45,6 @@ class _SleepFormState extends State<SleepForm> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
TimePicker(TimeOfDay(hour: 22, minute: 00)),
|
|
||||||
ElevatedCard(sleepTimePicker),
|
ElevatedCard(sleepTimePicker),
|
||||||
ElevatedCard(wakeUpTimePicker),
|
ElevatedCard(wakeUpTimePicker),
|
||||||
ElevatedCard(slider),
|
ElevatedCard(slider),
|
||||||
|
|
|
@ -1,33 +1,32 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
// ignore: must_be_immutable
|
||||||
class TimePicker extends StatefulWidget {
|
class TimePicker extends StatefulWidget {
|
||||||
final TimeOfDay _initialTime;
|
TimeOfDay _initialTime;
|
||||||
const TimePicker(this._initialTime, {super.key});
|
final String descriptionText;
|
||||||
|
TimePicker(this._initialTime, {super.key, required this.descriptionText});
|
||||||
|
|
||||||
|
TimeOfDay get getCurrentTime => _initialTime;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _TimePickerState();
|
State<StatefulWidget> createState() => TimePickerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TimePickerState extends State<TimePicker> {
|
class TimePickerState extends State<TimePicker> {
|
||||||
TimeOfDay time = const TimeOfDay(hour: 12, minute: 0);
|
TimePickerState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Center(
|
||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
const Text(
|
Text(
|
||||||
'Das ist die Zeit',
|
widget.descriptionText,
|
||||||
style: TextStyle(fontSize: 18),
|
style: TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||||
Text(
|
Text(
|
||||||
'${time.hour}:${time.minute}',
|
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
|
||||||
style: const TextStyle(fontSize: 32),
|
style: const TextStyle(fontSize: 22),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
|
@ -35,7 +34,7 @@ class _TimePickerState extends State<TimePicker> {
|
||||||
//TODO auslagern
|
//TODO auslagern
|
||||||
TimeOfDay? newTime = await showTimePicker(
|
TimeOfDay? newTime = await showTimePicker(
|
||||||
context: context,
|
context: context,
|
||||||
initialTime: time,
|
initialTime: widget._initialTime,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context)
|
data: MediaQuery.of(context)
|
||||||
|
@ -46,8 +45,7 @@ class _TimePickerState extends State<TimePicker> {
|
||||||
);
|
);
|
||||||
if (newTime == null) return;
|
if (newTime == null) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
time = newTime;
|
widget._initialTime = newTime;
|
||||||
print('Zeit geändert $newTime, Zeit aktualisiert?: $time');
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: const Text('Zeit einstellen'))
|
child: const Text('Zeit einstellen'))
|
||||||
|
|
Loading…
Reference in New Issue