Update Tasks when Settings update
parent
1a7f98c538
commit
d18bf8f56d
|
@ -29,7 +29,11 @@ class MyApp extends StatelessWidget {
|
||||||
home: MultiProvider(
|
home: MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (context) => SettingsProvider()),
|
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(),
|
child: const MyHomePage(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:smoke_cess_app/models/sleep.dart';
|
import 'package:smoke_cess_app/models/sleep.dart';
|
||||||
import 'package:smoke_cess_app/models/workout.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/date_service.dart';
|
||||||
import 'package:smoke_cess_app/services/pages_service.dart';
|
import 'package:smoke_cess_app/services/pages_service.dart';
|
||||||
import 'package:timezone/browser.dart';
|
import 'package:timezone/browser.dart';
|
||||||
|
@ -14,7 +15,7 @@ class TasksProvider extends ChangeNotifier {
|
||||||
Pages.timer: true,
|
Pages.timer: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
TasksProvider() {
|
TasksProvider(SettingsProvider? settingsProvider) {
|
||||||
initTasks();
|
initTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,17 +30,17 @@ class TasksProvider extends ChangeNotifier {
|
||||||
List<Mood> moodList = await globals.databaseService.getMoodRecords();
|
List<Mood> moodList = await globals.databaseService.getMoodRecords();
|
||||||
if (moodList.isNotEmpty) {
|
if (moodList.isNotEmpty) {
|
||||||
Mood mood = moodList.last;
|
Mood mood = moodList.last;
|
||||||
tasks[Pages.mood] = isSameDay(moodToday, mood.date);
|
tasks[Pages.mood] = !isSameDay(moodToday, mood.date);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tasks[Pages.mood] = false;
|
tasks[Pages.mood] = false;
|
||||||
}
|
}
|
||||||
TZDateTime? sleepToday = await getTodayMood();
|
TZDateTime? sleepToday = await getTodaySleep();
|
||||||
if (sleepToday != null) {
|
if (sleepToday != null) {
|
||||||
List<Sleep> sleepList = await globals.databaseService.getSleepRecords();
|
List<Sleep> sleepList = await globals.databaseService.getSleepRecords();
|
||||||
if (sleepList.isNotEmpty) {
|
if (sleepList.isNotEmpty) {
|
||||||
Sleep sleep = sleepList.last;
|
Sleep sleep = sleepList.last;
|
||||||
tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date);
|
tasks[Pages.sleep] = !isSameDay(sleepToday, sleep.date);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tasks[Pages.sleep] = false;
|
tasks[Pages.sleep] = false;
|
||||||
|
@ -48,7 +49,7 @@ class TasksProvider extends ChangeNotifier {
|
||||||
await globals.databaseService.getWorkoutRecords();
|
await globals.databaseService.getWorkoutRecords();
|
||||||
if (workoutList.isNotEmpty) {
|
if (workoutList.isNotEmpty) {
|
||||||
Workout mood = workoutList.last;
|
Workout mood = workoutList.last;
|
||||||
tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date);
|
tasks[Pages.timer] = !isSameDay(DateTime.now(), mood.date);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue