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(); }