Nice Cards and silder with input
parent
f0e2ce16f2
commit
0d4e7e4a92
|
@ -48,32 +48,40 @@ class _SleepFormState extends State<SleepForm> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
child: sleepTimePicker,
|
|
||||||
title: 'Einschlafzeit',
|
title: 'Einschlafzeit',
|
||||||
|
child: sleepTimePicker,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
child: wakeUpTimePicker,
|
|
||||||
title: 'Aufwachzeit',
|
title: 'Aufwachzeit',
|
||||||
|
child: wakeUpTimePicker,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
child: slider,
|
|
||||||
title: 'Schlafbewertung',
|
title: 'Schlafbewertung',
|
||||||
|
child: slider,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
|
title: 'Schlafbeschreibung',
|
||||||
child: MyTextFormField(
|
child: MyTextFormField(
|
||||||
'Beschreibe deinen Schlaf', onFormFieldSave),
|
'Beschreibe deinen Schlaf', onFormFieldSave),
|
||||||
title: 'Schlafbeschreibung',
|
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 32,
|
height: 80,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SubmitFormButton(submitForm),
|
Positioned(
|
||||||
|
bottom: 0,
|
||||||
|
right: 0,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 140,
|
||||||
|
height: 80,
|
||||||
|
child: SubmitFormButton(submitForm),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,7 @@ double _currentSliderValue = 50;
|
||||||
|
|
||||||
class MySlider extends StatefulWidget {
|
class MySlider extends StatefulWidget {
|
||||||
final String _title;
|
final String _title;
|
||||||
const MySlider(this._title, {super.key});
|
const MySlider(this._title, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => SliderState();
|
State<StatefulWidget> createState() => SliderState();
|
||||||
|
@ -21,23 +21,22 @@ class SliderState extends State<MySlider> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_textFieldController.text = _currentSliderValue.toString();
|
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Center(
|
||||||
children: [
|
child: Column(
|
||||||
Text(widget._title),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Row(
|
children: [
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
Text(widget._title),
|
||||||
children: [
|
SizedBox(height: 16),
|
||||||
SliderTheme(
|
Row(
|
||||||
data: SliderThemeData(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0),
|
children: [
|
||||||
trackHeight: 2.0,
|
Expanded(
|
||||||
),
|
child: Slider(
|
||||||
child: Slider(
|
|
||||||
value: _currentSliderValue,
|
value: _currentSliderValue,
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 100,
|
max: 100,
|
||||||
|
@ -46,49 +45,50 @@ class SliderState extends State<MySlider> {
|
||||||
onChanged: (double value) {
|
onChanged: (double value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentSliderValue = value;
|
_currentSliderValue = value;
|
||||||
_textFieldController.text =
|
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
|
||||||
_currentSliderValue.toString();
|
|
||||||
_errorText = null;
|
_errorText = null;
|
||||||
});
|
});
|
||||||
}),
|
},
|
||||||
),
|
|
||||||
SizedBox(width: 16.0),
|
|
||||||
SizedBox(
|
|
||||||
width: 50,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _textFieldController,
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Enter value',
|
|
||||||
errorText: _errorText,
|
|
||||||
),
|
),
|
||||||
onChanged: (text) {
|
),
|
||||||
if (text.isEmpty) {
|
SizedBox(width: 16),
|
||||||
_currentSliderValue = 0;
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _textFieldController,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Stimmung',
|
||||||
|
errorText: _errorText,
|
||||||
|
),
|
||||||
|
onChanged: (text) {
|
||||||
|
if (text.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
_currentSliderValue = 1;
|
||||||
|
_textFieldController.clear();
|
||||||
|
_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(() {
|
setState(() {
|
||||||
|
_currentSliderValue = value;
|
||||||
_errorText = null;
|
_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;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue