feat: add DailyStatusRepository for managing and persisting state

- Also add model for DailyStatus
This commit is contained in:
Liat Ben-Haim 2023-06-03 14:54:47 +02:00
parent d1b97dc621
commit fca1b565f5
2 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,51 @@
import 'models/daily_entry_model.dart';
class DailyStatusRepository {
DailyEntry? currentDay;
DailyStatusRepository();
void logFeelingMigrainy(bool status) {
if (currentDay == null) {
currentDay = DailyEntry(
date: getCurrentDate(),
feelingMigrainy: status,
tookZomig: false,
hadMigraine: false,
tookPainMeds: false);
} else {
currentDay = DailyEntry(
date: getCurrentDate(),
feelingMigrainy: status,
tookZomig: currentDay!.tookZomig,
hadMigraine: currentDay!.hadMigraine,
tookPainMeds: currentDay!.tookPainMeds
);
}
}
void logTookZomig(bool status) {
if (currentDay == null) {
currentDay = DailyEntry(
date: getCurrentDate(),
feelingMigrainy: false,
tookZomig: status,
hadMigraine: false,
tookPainMeds: false);
} else {
currentDay = DailyEntry(
date: getCurrentDate(),
feelingMigrainy: currentDay!.tookZomig,
tookZomig: status,
hadMigraine: currentDay!.hadMigraine,
tookPainMeds: currentDay!.tookPainMeds
);
}
}
DateTime getCurrentDate() {
DateTime now = DateTime.now();
DateTime date = DateTime(now.year, now.month, now.day);
return date;
}
}

View file

@ -0,0 +1,15 @@
class DailyEntry {
final DateTime date;
final bool feelingMigrainy;
final bool tookZomig;
final bool hadMigraine;
final bool tookPainMeds;
const DailyEntry({
required this.date,
required this.feelingMigrainy,
required this.tookZomig,
required this.hadMigraine,
required this.tookPainMeds});
}