From d18bf8f56d372e1c3b19036537c6cedd6a777305 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:57:24 +0100 Subject: [PATCH] Update Tasks when Settings update --- lib/main.dart | 6 +++++- lib/providers/tasks_provider.dart | 11 ++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0c574ce..c5a19b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,7 +29,11 @@ class MyApp extends StatelessWidget { home: MultiProvider( providers: [ ChangeNotifierProvider(create: (context) => SettingsProvider()), - ChangeNotifierProvider(create: (context) => TasksProvider()), + ChangeNotifierProxyProvider( + create: (context) => TasksProvider(null), + update: (context, value, TasksProvider? previous) => + TasksProvider(value), + ), ], child: const MyHomePage(), )); diff --git a/lib/providers/tasks_provider.dart b/lib/providers/tasks_provider.dart index 182b8ec..8ae2a04 100644 --- a/lib/providers/tasks_provider.dart +++ b/lib/providers/tasks_provider.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:smoke_cess_app/models/sleep.dart'; import 'package:smoke_cess_app/models/workout.dart'; +import 'package:smoke_cess_app/providers/settings_provider.dart'; import 'package:smoke_cess_app/services/date_service.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:timezone/browser.dart'; @@ -14,7 +15,7 @@ class TasksProvider extends ChangeNotifier { Pages.timer: true, }; - TasksProvider() { + TasksProvider(SettingsProvider? settingsProvider) { initTasks(); } @@ -29,17 +30,17 @@ class TasksProvider extends ChangeNotifier { List moodList = await globals.databaseService.getMoodRecords(); if (moodList.isNotEmpty) { Mood mood = moodList.last; - tasks[Pages.mood] = isSameDay(moodToday, mood.date); + tasks[Pages.mood] = !isSameDay(moodToday, mood.date); } } else { tasks[Pages.mood] = false; } - TZDateTime? sleepToday = await getTodayMood(); + TZDateTime? sleepToday = await getTodaySleep(); if (sleepToday != null) { List sleepList = await globals.databaseService.getSleepRecords(); if (sleepList.isNotEmpty) { Sleep sleep = sleepList.last; - tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date); + tasks[Pages.sleep] = !isSameDay(sleepToday, sleep.date); } } else { tasks[Pages.sleep] = false; @@ -48,7 +49,7 @@ class TasksProvider extends ChangeNotifier { await globals.databaseService.getWorkoutRecords(); if (workoutList.isNotEmpty) { Workout mood = workoutList.last; - tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date); + tasks[Pages.timer] = !isSameDay(DateTime.now(), mood.date); } notifyListeners(); }