Parricc35 2023-02-20 23:59:40 +01:00
parent c9e57b06d6
commit f5ef084997
5 changed files with 144 additions and 62 deletions

View File

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

View File

@ -1,17 +1,37 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ElevatedCard extends StatelessWidget { class ElevatedCard extends StatelessWidget {
final Widget? _child; final Widget child;
const ElevatedCard(this._child, {super.key}); final String title;
const ElevatedCard({
Key? key,
required this.child,
required this.title,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Card(
child: Card( elevation: 4.0,
child: SizedBox( shape: RoundedRectangleBorder(
width: 300, borderRadius: BorderRadius.circular(16.0),
height: 100, ),
child: _child, child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8.0),
child,
],
), ),
), ),
); );

View File

@ -6,7 +6,7 @@ import 'package:smoke_cess_app/widgets/text_formfield.dart';
import 'package:smoke_cess_app/widgets/timepicker.dart'; import 'package:smoke_cess_app/widgets/timepicker.dart';
class SleepForm extends StatefulWidget { class SleepForm extends StatefulWidget {
const SleepForm({super.key}); const SleepForm({Key? key}) : super(key: key);
@override @override
State<SleepForm> createState() => _SleepFormState(); State<SleepForm> createState() => _SleepFormState();
@ -14,21 +14,18 @@ class SleepForm extends StatefulWidget {
class _SleepFormState extends State<SleepForm> { 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('');
String _textInput = ""; String _textInput = "";
TimePicker sleepTimePicker = TimePicker( TimePicker sleepTimePicker = TimePicker(
const TimeOfDay(hour: 22, minute: 00), const TimeOfDay(hour: 22, minute: 00),
descriptionText: 'eingeschlafen um',
); );
TimePicker wakeUpTimePicker = TimePicker( TimePicker wakeUpTimePicker = TimePicker(
const TimeOfDay(hour: 8, minute: 00), const TimeOfDay(hour: 8, minute: 00),
descriptionText: 'aufgewacht um',
); );
void submitForm() { void submitForm() {
if (_sleepFormKey.currentState!.validate()) { if (_sleepFormKey.currentState!.validate()) {
_sleepFormKey.currentState?.save(); //call every onSave Method _sleepFormKey.currentState?.save();
//TODO Businesslogik aufrufen!
print(_textInput); print(_textInput);
print(slider.getSliderValue()); print(slider.getSliderValue());
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
@ -42,16 +39,42 @@ class _SleepFormState extends State<SleepForm> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Form( return Form(
key: _sleepFormKey, key: _sleepFormKey,
child: Stack(
children: [
SingleChildScrollView(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
ElevatedCard(sleepTimePicker),
ElevatedCard(wakeUpTimePicker),
ElevatedCard(slider),
ElevatedCard( ElevatedCard(
MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave)), child: sleepTimePicker,
SubmitFormButton(submitForm) 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),
],
),
);
} }
} }

View File

@ -15,6 +15,15 @@ class MySlider extends StatefulWidget {
} }
class SliderState extends State<MySlider> { class SliderState extends State<MySlider> {
TextEditingController _textFieldController = TextEditingController();
String? _errorText;
@override
void initState() {
super.initState();
_textFieldController.text = _currentSliderValue.toString();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
@ -25,13 +34,50 @@ class SliderState extends State<MySlider> {
children: [ children: [
Slider( Slider(
value: _currentSliderValue, value: _currentSliderValue,
min: 1,
max: 100, max: 100,
divisions: 99,
label: _currentSliderValue.round().toString(), label: _currentSliderValue.round().toString(),
onChanged: (double value) => onChanged: (double value) {
{setState((() => _currentSliderValue = value))}), setState(() {
_currentSliderValue = value;
_textFieldController.text = _currentSliderValue.toString();
_errorText = null;
});
}),
Text(_currentSliderValue.round().toString()) Text(_currentSliderValue.round().toString())
], ],
) ),
SizedBox(height: 16),
TextFormField(
controller: _textFieldController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter value',
errorText: _errorText,
),
onChanged: (text) {
if (text.isEmpty) {
_currentSliderValue = 0;
setState(() {
_errorText = null;
});
return;
}
final value = double.tryParse(text);
if (value == null || value < 1 || value > 100) {
setState(() {
_textFieldController.clear();
_errorText = 'Please enter a value between 1 and 100.';
});
return;
}
setState(() {
_currentSliderValue = value;
_errorText = null;
});
},
),
], ],
); );
} }

View File

@ -3,8 +3,7 @@ import 'package:flutter/material.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class TimePicker extends StatefulWidget { class TimePicker extends StatefulWidget {
TimeOfDay _initialTime; TimeOfDay _initialTime;
final String descriptionText; TimePicker(this._initialTime, {Key? key});
TimePicker(this._initialTime, {super.key, required this.descriptionText});
TimeOfDay get getCurrentTime => _initialTime; TimeOfDay get getCurrentTime => _initialTime;
@ -18,12 +17,7 @@ class TimePickerState extends State<TimePicker> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Center(
child: Column(children: [ child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
widget.descriptionText,
style: TextStyle(fontSize: 12),
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text( Text(
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}', '${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 22), style: const TextStyle(fontSize: 22),
@ -49,7 +43,6 @@ class TimePickerState extends State<TimePicker> {
}); });
}, },
child: const Text('Zeit einstellen')) child: const Text('Zeit einstellen'))
])
]), ]),
); );
} }