Enhance Pad Tracking with new Flow and Supply logic

This commit is contained in:
2026-01-09 13:35:07 -06:00
parent 24ffac2415
commit dc6bcad83f
17 changed files with 765 additions and 171 deletions

View File

@@ -157,26 +157,41 @@ class CycleService {
}
// Handle cases where last period was long ago (more than one cycle)
final dayOfCycle = ((daysSinceLastPeriod - 1) % cycleLength) + 1;
final daysUntilPeriod = cycleLength - dayOfCycle;
final int calculatedDayOfCycle =
((daysSinceLastPeriod - 1) % cycleLength) + 1;
// Check if we are in the predicted menstrual phase but no period is logged
bool isPeriodLoggedToday =
entries.any((e) => DateUtils.isSameDay(e.date, now) && e.isPeriodDay);
CyclePhase phase;
if (dayOfCycle <= user.averagePeriodLength) {
// Use variable period length
phase = CyclePhase.menstrual;
} else if (dayOfCycle <= 13) {
int dayOfCycle = calculatedDayOfCycle;
if (calculatedDayOfCycle <= user.averagePeriodLength) {
if (isPeriodLoggedToday) {
phase = CyclePhase.menstrual;
} else {
// No period logged today, but we are in the predicted window.
// Stay in Luteal and extend the day count.
phase = CyclePhase.luteal;
dayOfCycle = daysSinceLastPeriod;
}
} else if (calculatedDayOfCycle <= 13) {
phase = CyclePhase.follicular;
} else if (dayOfCycle <= 16) {
} else if (calculatedDayOfCycle <= 16) {
phase = CyclePhase.ovulation;
} else {
phase = CyclePhase.luteal;
}
final daysUntilPeriod =
dayOfCycle >= cycleLength ? 0 : cycleLength - dayOfCycle;
return CycleInfo(
phase: phase,
dayOfCycle: dayOfCycle,
daysUntilPeriod: daysUntilPeriod,
isPeriodExpected: daysUntilPeriod <= 0 || dayOfCycle <= 5,
isPeriodExpected: daysUntilPeriod <= 0 || calculatedDayOfCycle <= 5,
);
}