wip
parent
c9e57b06d6
commit
f5ef084997
|
@ -6,6 +6,6 @@ class SleepPage extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(child: SleepForm());
|
||||
return const Center(child: SleepForm());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class ElevatedCard extends StatelessWidget {
|
||||
final Widget? _child;
|
||||
const ElevatedCard(this._child, {super.key});
|
||||
final Widget child;
|
||||
final String title;
|
||||
|
||||
const ElevatedCard({
|
||||
Key? key,
|
||||
required this.child,
|
||||
required this.title,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Card(
|
||||
child: SizedBox(
|
||||
width: 300,
|
||||
height: 100,
|
||||
child: _child,
|
||||
return Card(
|
||||
elevation: 4.0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
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,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
|||
import 'package:smoke_cess_app/widgets/timepicker.dart';
|
||||
|
||||
class SleepForm extends StatefulWidget {
|
||||
const SleepForm({super.key});
|
||||
const SleepForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SleepForm> createState() => _SleepFormState();
|
||||
|
@ -14,21 +14,18 @@ class SleepForm extends StatefulWidget {
|
|||
|
||||
class _SleepFormState extends State<SleepForm> {
|
||||
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
||||
MySlider slider = const MySlider('Bewerte deinen Schlaf');
|
||||
MySlider slider = const MySlider('');
|
||||
String _textInput = "";
|
||||
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()) {
|
||||
_sleepFormKey.currentState?.save(); //call every onSave Method
|
||||
//TODO Businesslogik aufrufen!
|
||||
_sleepFormKey.currentState?.save();
|
||||
print(_textInput);
|
||||
print(slider.getSliderValue());
|
||||
print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}');
|
||||
|
@ -42,16 +39,42 @@ class _SleepFormState extends State<SleepForm> {
|
|||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _sleepFormKey,
|
||||
child: Stack(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ElevatedCard(sleepTimePicker),
|
||||
ElevatedCard(wakeUpTimePicker),
|
||||
ElevatedCard(slider),
|
||||
ElevatedCard(
|
||||
MyTextFormField('Beschreibe deinen Schlaf', onFormFieldSave)),
|
||||
SubmitFormButton(submitForm)
|
||||
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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,15 @@ class MySlider extends StatefulWidget {
|
|||
}
|
||||
|
||||
class SliderState extends State<MySlider> {
|
||||
TextEditingController _textFieldController = TextEditingController();
|
||||
String? _errorText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_textFieldController.text = _currentSliderValue.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
|
@ -25,13 +34,50 @@ class SliderState extends State<MySlider> {
|
|||
children: [
|
||||
Slider(
|
||||
value: _currentSliderValue,
|
||||
min: 1,
|
||||
max: 100,
|
||||
divisions: 99,
|
||||
label: _currentSliderValue.round().toString(),
|
||||
onChanged: (double value) =>
|
||||
{setState((() => _currentSliderValue = value))}),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_currentSliderValue = value;
|
||||
_textFieldController.text = _currentSliderValue.toString();
|
||||
_errorText = null;
|
||||
});
|
||||
}),
|
||||
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;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@ import 'package:flutter/material.dart';
|
|||
// ignore: must_be_immutable
|
||||
class TimePicker extends StatefulWidget {
|
||||
TimeOfDay _initialTime;
|
||||
final String descriptionText;
|
||||
TimePicker(this._initialTime, {super.key, required this.descriptionText});
|
||||
TimePicker(this._initialTime, {Key? key});
|
||||
|
||||
TimeOfDay get getCurrentTime => _initialTime;
|
||||
|
||||
|
@ -18,12 +17,7 @@ class TimePickerState extends State<TimePicker> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(children: [
|
||||
Text(
|
||||
widget.descriptionText,
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Text(
|
||||
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
|
||||
style: const TextStyle(fontSize: 22),
|
||||
|
@ -49,7 +43,6 @@ class TimePickerState extends State<TimePicker> {
|
|||
});
|
||||
},
|
||||
child: const Text('Zeit einstellen'))
|
||||
])
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue