Merge branch 'feature/ZI-7/mood-page' into 'main'

Feature/zi 7/mood page

See merge request Crondung/hsma_cpd!2
main
Parricc35 2023-02-16 08:42:20 +00:00
commit 9199856d2c
6 changed files with 130 additions and 2 deletions

View File

@ -14,6 +14,13 @@ class MyHomePage extends StatefulWidget {
class MyHomePageState extends State<MyHomePage> { class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 2; int _selectedIndex = 2;
final List<String> _titles = [
'Stimmung',
'Schlaf',
'Timer',
'Rückfall',
'Einstellungen'
];
static const List<Widget> _widgetOptions = <Widget>[ static const List<Widget> _widgetOptions = <Widget>[
MoodPage(), MoodPage(),
SleepPage(), SleepPage(),
@ -29,7 +36,7 @@ class MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('ZI Rauchentwöhnung')), appBar: AppBar(title: Text(_titles[_selectedIndex])),
body: _widgetOptions.elementAt(_selectedIndex), body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,

View File

@ -1,10 +1,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.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 const Center(child: Text('Hier Fragen wir die Stimmung ab')); return const Center(
child: MoodForm(),
);
} }
} }

View File

@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/widgets/slider.dart';
import 'package:smoke_cess_app/widgets/submit_form_button.dart';
import 'package:smoke_cess_app/widgets/text_formfield.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 = "";
void submitForm() {
if (_moodFormKey.currentState!.validate()) {
_moodFormKey.currentState?.save(); //call every onSave Method
//TODO Businesslogik aufrufen!
print(_textInput);
print(slider.getSliderValue());
_moodFormKey.currentState?.reset();
}
}
void onFormFieldSave(String? newValue) => _textInput = newValue!;
@override
Widget build(BuildContext context) {
return Form(
key: _moodFormKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
slider,
MyTextFormField(onFormFieldSave),
SubmitFormButton(submitForm)
],
));
}
}

View File

@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
double _currentSliderValue = 50;
class MySlider extends StatefulWidget {
const MySlider({super.key});
@override
State<StatefulWidget> createState() => SliderState();
double getSliderValue() {
return _currentSliderValue;
}
}
class SliderState extends State<MySlider> {
@override
Widget build(BuildContext context) {
return Column(
children: [
const Text('Bewerte deine Stimmung'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Slider(
value: _currentSliderValue,
max: 100,
label: _currentSliderValue.round().toString(),
onChanged: (double value) =>
{setState((() => _currentSliderValue = value))}),
Text(_currentSliderValue.round().toString())
],
)
],
);
}
}

View File

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class SubmitFormButton extends StatelessWidget {
final VoidCallback submitCallback;
const SubmitFormButton(this.submitCallback, {super.key});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: submitCallback,
child: const Text('Speichern'),
),
);
}
}

View File

@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
class MyTextFormField extends StatelessWidget {
final Function(String?) onSaveAction;
const MyTextFormField(
this.onSaveAction, {
super.key,
});
@override
Widget build(BuildContext context) {
return TextFormField(
onSaved: onSaveAction,
decoration: const InputDecoration(hintText: 'Beschreibe deine Stimmung?'),
validator: (String? value) =>
value == null || value.isEmpty ? 'Text eingeben' : null,
keyboardType: TextInputType.multiline,
maxLines: null,
);
}
}