implemented form for mood
parent
92333d7b2d
commit
465b4504a9
|
@ -1,11 +1,13 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:smoke_cess_app/widgets/slider.dart';
|
import 'package:smoke_cess_app/widgets/mood_form.dart';
|
||||||
|
|
||||||
class MoodPage extends StatelessWidget {
|
class MoodPage extends StatelessWidget {
|
||||||
const MoodPage({super.key});
|
const MoodPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(children: const [MySlider(), Text('Freitext')]);
|
return const Center(
|
||||||
|
child: MoodForm(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:smoke_cess_app/widgets/slider.dart';
|
||||||
|
|
||||||
|
class MoodForm extends StatefulWidget {
|
||||||
|
const MoodForm({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MoodForm> createState() => _MoodFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MoodFormState extends State<MoodForm> {
|
||||||
|
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
||||||
|
MySlider slider = const MySlider();
|
||||||
|
String _textInput = "";
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Form(
|
||||||
|
key: _moodFormKey,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
slider,
|
||||||
|
TextFormField(
|
||||||
|
onSaved: (newValue) => _textInput = newValue!,
|
||||||
|
decoration:
|
||||||
|
const InputDecoration(hintText: 'Beschreibe deine Stimmung?'),
|
||||||
|
validator: (String? value) =>
|
||||||
|
value == null || value.isEmpty ? 'Text eingeben' : null,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
maxLines: null,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (_moodFormKey.currentState!.validate()) {
|
||||||
|
_moodFormKey.currentState
|
||||||
|
?.save(); //call every onSave Method
|
||||||
|
print(_textInput);
|
||||||
|
print(slider.getSliderValue());
|
||||||
|
_moodFormKey.currentState?.reset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Speichern'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,18 +1,26 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
double _currentSliderValue = 50;
|
||||||
|
|
||||||
class MySlider extends StatefulWidget {
|
class MySlider extends StatefulWidget {
|
||||||
const MySlider({super.key});
|
const MySlider({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => SliderState();
|
State<StatefulWidget> createState() => SliderState();
|
||||||
|
|
||||||
|
double getSliderValue() {
|
||||||
|
return _currentSliderValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SliderState extends State<MySlider> {
|
class SliderState extends State<MySlider> {
|
||||||
double _currentSliderValue = 50;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Column(
|
||||||
|
children: [
|
||||||
|
const Text('Bewerte deine Stimmung'),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Slider(
|
Slider(
|
||||||
value: _currentSliderValue,
|
value: _currentSliderValue,
|
||||||
|
@ -22,6 +30,8 @@ class SliderState extends State<MySlider> {
|
||||||
{setState((() => _currentSliderValue = value))}),
|
{setState((() => _currentSliderValue = value))}),
|
||||||
Text(_currentSliderValue.round().toString())
|
Text(_currentSliderValue.round().toString())
|
||||||
],
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue