Nice Cards and silder with input

main
Parricc35 2023-02-21 13:39:06 +01:00
parent f0e2ce16f2
commit 0d4e7e4a92
2 changed files with 64 additions and 56 deletions

View File

@ -48,32 +48,40 @@ class _SleepFormState extends State<SleepForm> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ElevatedCard(
child: sleepTimePicker,
title: 'Einschlafzeit',
child: sleepTimePicker,
),
const SizedBox(height: 16),
ElevatedCard(
child: wakeUpTimePicker,
title: 'Aufwachzeit',
child: wakeUpTimePicker,
),
const SizedBox(height: 16),
ElevatedCard(
child: slider,
title: 'Schlafbewertung',
child: slider,
),
const SizedBox(height: 16),
ElevatedCard(
title: 'Schlafbeschreibung',
child: MyTextFormField(
'Beschreibe deinen Schlaf', onFormFieldSave),
title: 'Schlafbeschreibung',
),
const SizedBox(
height: 32,
height: 80,
),
],
),
),
SubmitFormButton(submitForm),
Positioned(
bottom: 0,
right: 0,
child: SizedBox(
width: 140,
height: 80,
child: SubmitFormButton(submitForm),
),
),
],
),
);

View File

@ -4,7 +4,7 @@ double _currentSliderValue = 50;
class MySlider extends StatefulWidget {
final String _title;
const MySlider(this._title, {super.key});
const MySlider(this._title, {Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => SliderState();
@ -21,23 +21,22 @@ class SliderState extends State<MySlider> {
@override
void initState() {
super.initState();
_textFieldController.text = _currentSliderValue.toString();
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(widget._title),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SliderTheme(
data: SliderThemeData(
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0),
trackHeight: 2.0,
),
child: Slider(
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(widget._title),
SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Slider(
value: _currentSliderValue,
min: 1,
max: 100,
@ -46,49 +45,50 @@ class SliderState extends State<MySlider> {
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
_textFieldController.text =
_currentSliderValue.toString();
_textFieldController.text = _currentSliderValue.toStringAsFixed(0);
_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) {
_currentSliderValue = 0;
),
SizedBox(width: 16),
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(() {
_currentSliderValue = value;
_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;
});
},
},
),
),
),
],
),
],
],
),
],
),
);
}
}