56 lines
1.7 KiB
Dart
56 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:smoke_cess_app/models/mood.dart';
|
|
import 'package:smoke_cess_app/service/database_service.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';
|
|
|
|
import 'elevated_card.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
|
|
Mood mood =
|
|
Mood(slider.getSliderValue().toInt(), _textInput, DateTime.now());
|
|
DatabaseService.instance.addMood(mood);
|
|
_moodFormKey.currentState?.reset();
|
|
}
|
|
}
|
|
|
|
void onFormFieldSave(String? newValue) => _textInput = newValue!;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Form(
|
|
key: _moodFormKey,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
ElevatedCard(
|
|
title: 'Stimmungsbewertung',
|
|
child: slider,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedCard(
|
|
title: 'Beschreibe deine Stimmung',
|
|
child:
|
|
MyTextFormField('Beschreibe deine Stimmung', onFormFieldSave),
|
|
),
|
|
SubmitFormButton(submitForm)
|
|
],
|
|
));
|
|
}
|
|
}
|