feat: add DailyStatusRepository for managing and persisting state
- Also add model for DailyStatus
This commit is contained in:
parent
d1b97dc621
commit
fca1b565f5
2 changed files with 66 additions and 0 deletions
51
lib/data_storage/daily_status_repository.dart
Normal file
51
lib/data_storage/daily_status_repository.dart
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
lib/data_storage/models/daily_entry_model.dart
Normal file
15
lib/data_storage/models/daily_entry_model.dart
Normal 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});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue