From 575a2bb90ebb7ee5d4a1cccd43fa964290603f2d Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Tue, 7 Mar 2023 00:49:54 +0100 Subject: [PATCH] Hotfix taksscheduling --- lib/globals.dart | 4 ++-- lib/providers/tasks_provider.dart | 10 ++++------ lib/widgets/view_form/relapse_form.dart | 2 +- lib/widgets/view_form/sleep_form.dart | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/globals.dart b/lib/globals.dart index cebeea2..ebfb8e3 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -4,8 +4,8 @@ library app.globals; import 'package:smoke_cess_app/mock/db_mock.dart'; import 'package:smoke_cess_app/services/database_service.dart'; -DatabaseService databaseService = DatabaseService.instance; -//DatabaseService databaseService = DatabaseMock(); +//DatabaseService databaseService = DatabaseService.instance; +DatabaseService databaseService = DatabaseMock(); // set this to read settings from local json file instead of scanning a qr code bool useLocalConfig = true; diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart index 17b2aa5..d412d39 100644 --- a/lib/providers/tasks_provider.dart +++ b/lib/providers/tasks_provider.dart @@ -42,23 +42,21 @@ class TasksProvider extends ChangeNotifier { void initTasks() async { DateTime now = DateTime.now(); TZDateTime? moodToday = await getTodayMood(); - if (moodToday != null) { + if (moodToday != null && moodToday.isBefore(now)) { List moodList = await globals.databaseService.getMoodRecords(); if (moodList.isNotEmpty) { Mood mood = moodList.last; - tasks[Pages.mood] = - !isSameDay(moodToday, mood.date) && moodToday.isBefore(now); + tasks[Pages.mood] = !isSameDay(moodToday, mood.date); } } else { tasks[Pages.mood] = false; } TZDateTime? sleepToday = await getTodaySleep(); - if (sleepToday != null) { + if (sleepToday != null && sleepToday.isBefore(now)) { List sleepList = await globals.databaseService.getSleepRecords(); if (sleepList.isNotEmpty) { Sleep sleep = sleepList.last; - tasks[Pages.sleep] = - !isSameDay(sleepToday, sleep.date) && sleepToday.isBefore(now); + tasks[Pages.sleep] = !isSameDay(sleepToday, sleep.date); } } else { tasks[Pages.sleep] = false; diff --git a/lib/widgets/view_form/relapse_form.dart b/lib/widgets/view_form/relapse_form.dart index 6131880..b15721e 100644 --- a/lib/widgets/view_form/relapse_form.dart +++ b/lib/widgets/view_form/relapse_form.dart @@ -30,7 +30,7 @@ class RelapseForm extends StatelessWidget { ), SubmitFormButton( submitCallback: inputModel.saveRelapse, - updateTasks: () => tasksModel.setTaskDone(Pages.mood), + updateTasks: () => tasksModel.setTaskDone(Pages.relapse), ) ], ); diff --git a/lib/widgets/view_form/sleep_form.dart b/lib/widgets/view_form/sleep_form.dart index a9998ec..18ae14c 100644 --- a/lib/widgets/view_form/sleep_form.dart +++ b/lib/widgets/view_form/sleep_form.dart @@ -43,7 +43,7 @@ class SleepForm extends StatelessWidget { SubmitFormButton( submitCallback: () => inputModel.saveSleep(SleepTimes.wokeUpAt, SleepTimes.sleptAt), - updateTasks: () => tasksModel.setTaskDone(Pages.mood), + updateTasks: () => tasksModel.setTaskDone(Pages.sleep), ) ], );