56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
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/services/date_service.dart';
|
|
import 'package:smoke_cess_app/services/pages_service.dart';
|
|
import 'package:timezone/browser.dart';
|
|
import '../globals.dart' as globals;
|
|
import '../models/mood.dart';
|
|
|
|
class TasksProvider extends ChangeNotifier {
|
|
Map<Pages, bool> tasks = {
|
|
Pages.mood: true,
|
|
Pages.sleep: true,
|
|
Pages.timer: true,
|
|
};
|
|
|
|
TasksProvider() {
|
|
initTasks();
|
|
}
|
|
|
|
void setTaksDone(Pages taskName) {
|
|
tasks[taskName] = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
void initTasks() async {
|
|
TZDateTime? moodToday = await getTodayMood();
|
|
if (moodToday != null) {
|
|
List<Mood> moodList = await globals.databaseService.getMoodRecords();
|
|
if (moodList.isNotEmpty) {
|
|
Mood mood = moodList.last;
|
|
tasks[Pages.mood] = isSameDay(moodToday, mood.date);
|
|
}
|
|
} else {
|
|
tasks[Pages.mood] = false;
|
|
}
|
|
TZDateTime? sleepToday = await getTodayMood();
|
|
if (sleepToday != null) {
|
|
List<Sleep> sleepList = await globals.databaseService.getSleepRecords();
|
|
if (sleepList.isNotEmpty) {
|
|
Sleep sleep = sleepList.last;
|
|
tasks[Pages.sleep] = isSameDay(sleepToday, sleep.date);
|
|
}
|
|
} else {
|
|
tasks[Pages.sleep] = false;
|
|
}
|
|
List<Workout> workoutList =
|
|
await globals.databaseService.getWorkoutRecords();
|
|
if (workoutList.isNotEmpty) {
|
|
Workout mood = workoutList.last;
|
|
tasks[Pages.timer] = isSameDay(DateTime.now(), mood.date);
|
|
}
|
|
notifyListeners();
|
|
}
|
|
}
|