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, 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),
),
),
], ],
), ),
); );

View File

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