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,22 +21,21 @@ 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(
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(widget._title),
SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SliderTheme(
data: SliderThemeData(
thumbShape: RoundSliderThumbShape(enabledThumbRadius: 8.0),
trackHeight: 2.0,
),
Expanded(
child: Slider(
value: _currentSliderValue,
min: 1,
@ -46,26 +45,27 @@ 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: 16),
SizedBox(
width: 50,
width: 100,
child: TextFormField(
controller: _textFieldController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter value',
labelText: 'Stimmung',
errorText: _errorText,
),
onChanged: (text) {
if (text.isEmpty) {
_currentSliderValue = 0;
setState(() {
_currentSliderValue = 1;
_textFieldController.clear();
_errorText = null;
});
return;
@ -74,8 +74,7 @@ class SliderState extends State<MySlider> {
if (value == null || value < 1 || value > 100) {
setState(() {
_textFieldController.clear();
_errorText =
'Please enter a value between 1 and 100.';
_errorText = 'Please enter a value between 1 and 100.';
});
return;
}
@ -89,6 +88,7 @@ class SliderState extends State<MySlider> {
],
),
],
),
);
}
}