From 265e17488921dd9871b6e7d4966d3b50cb4a6ac1 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sat, 25 Feb 2023 18:54:54 +0100 Subject: [PATCH] use int for slider value in form, save model on form complete --- lib/widgets/mood_form.dart | 4 ++-- lib/widgets/sleep_form.dart | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index ca9858e..205e4d6 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -22,8 +22,8 @@ class _MoodFormState extends State { void submitForm() { if (_moodFormKey.currentState!.validate()) { _moodFormKey.currentState?.save(); //call every onSave Method - Mood mood = Mood(slider.getSliderValue(), _textInput, DateTime.now()); - print(mood.toCSV()); + Mood mood = + Mood(slider.getSliderValue().toInt(), _textInput, DateTime.now()); DatabaseService.instance.addMood(mood); _moodFormKey.currentState?.reset(); } diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 52eefe8..5564c7d 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; +import 'package:smoke_cess_app/service/database_service.dart'; import 'package:smoke_cess_app/widgets/elevated_card.dart'; import 'package:smoke_cess_app/widgets/slider.dart'; import 'package:smoke_cess_app/widgets/submit_form_button.dart'; @@ -26,10 +28,13 @@ class _SleepFormState extends State { void submitForm() { if (_sleepFormKey.currentState!.validate()) { _sleepFormKey.currentState?.save(); //call every onSave Method - //TODO Businesslogik aufrufen! - print(_textInput); - print(slider.getSliderValue()); - print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); + Sleep sleep = Sleep( + slider.getSliderValue().toInt(), + _textInput, + DateTime.now(), + sleepTimePicker.getCurrentTime, + wakeUpTimePicker.getCurrentTime); + DatabaseService.instance.addSleep(sleep); _sleepFormKey.currentState?.reset(); } }