cpd_2022_zi/lib/providers/task_provider.dart

57 lines
1.8 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 TaskProvider extends ChangeNotifier {
TaskProvider() {
initTasks();
}
void setTaksDone(Pages taskName) {
pages[taskName]?['todo'] = false;
notifyListeners();
}
void initTasks() {
pages.forEach((key, value) async {
if (!value['todo']) {
switch (key) {
case Pages.mood:
TZDateTime? moodToday = await getTodayMood();
if (moodToday != null) {
List<Mood> moodList =
await globals.databaseService.getMoodRecords();
Mood mood = moodList.last;
pages[key]?['todo'] = !isSameDay(moodToday, mood.date);
}
break;
case Pages.sleep:
TZDateTime? sleepToday = await getTodayMood();
if (sleepToday != null) {
List<Sleep> sleepList =
await globals.databaseService.getSleepRecords();
Sleep sleep = sleepList.last;
pages[key]?['todo'] = !isSameDay(sleepToday, sleep.date);
}
break;
case Pages.timer:
{
List<Workout> workoutList =
await globals.databaseService.getWorkoutRecords();
Workout mood = workoutList.last;
pages[key]?['todo'] = !isSameDay(DateTime.now(), mood.date);
break;
}
default:
}
}
});
notifyListeners();
}
}