Update Tasks when Settings update

main
Kai Mannweiler 2023-03-02 19:57:24 +01:00
parent 1a7f98c538
commit d18bf8f56d
2 changed files with 11 additions and 6 deletions

View File

@ -29,7 +29,11 @@ class MyApp extends StatelessWidget {
home: MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => SettingsProvider()),
ChangeNotifierProvider(create: (context) => TasksProvider()),
ChangeNotifierProxyProvider<SettingsProvider, TasksProvider>(
create: (context) => TasksProvider(null),
update: (context, value, TasksProvider? previous) =>
TasksProvider(value),
),
],
child: const MyHomePage(),
));

View File

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