Refactor: Implement multi-item inventory for Pad Tracker and dynamic navigation
This commit is contained in:
@@ -112,7 +112,7 @@ class CycleHistoryScreen extends ConsumerWidget {
|
||||
),
|
||||
child: ListTile(
|
||||
title: Text(DateFormat.yMMMMEEEEd().format(entry.date)),
|
||||
subtitle: Text(_buildEntrySummary(entry)),
|
||||
subtitle: Text(_buildEntrySummary(entry, ref)),
|
||||
isThreeLine: true,
|
||||
),
|
||||
);
|
||||
@@ -123,11 +123,47 @@ class CycleHistoryScreen extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
String _buildEntrySummary(CycleEntry entry) {
|
||||
String _buildEntrySummary(CycleEntry entry, WidgetRef ref) {
|
||||
final summary = <String>[];
|
||||
if (entry.isPeriodDay) {
|
||||
summary.add('Period');
|
||||
|
||||
// Calculate Cycle Day / Phase
|
||||
// This is a simplified calculation. For accurate phase, we need cycle logic.
|
||||
// We'll calculate the 'Day of Cycle' by finding the most recent period start before this entry.
|
||||
|
||||
final allEntries = ref.read(cycleEntriesProvider);
|
||||
DateTime? lastPeriodStart;
|
||||
|
||||
// Inefficient for large lists but acceptable for now.
|
||||
// Optimization: Calculate this once or pass cycle context.
|
||||
final sortedEntries = List<CycleEntry>.from(allEntries)..sort((a,b) => a.date.compareTo(b.date));
|
||||
|
||||
for (var e in sortedEntries) {
|
||||
if (e.date.isAfter(entry.date)) break;
|
||||
if (e.isPeriodDay) {
|
||||
// If it's a period day and the previous day wasn't (or gap > 1), it's a start.
|
||||
// Simplified: Just take the period day closest to entry.
|
||||
// Actually, if 'entry' IS a period day, then it's Menstrual phase.
|
||||
// We'll just look for the last period day.
|
||||
lastPeriodStart = e.date; // continuously update to find the latest one <= entry.date
|
||||
// But we need the START of that period block.
|
||||
}
|
||||
}
|
||||
|
||||
// Better Approach: Use CycleService static helper if available, or just check entry props.
|
||||
if (entry.isPeriodDay) {
|
||||
summary.add('Menstrual Phase');
|
||||
} else if (lastPeriodStart != null) {
|
||||
final day = entry.date.difference(lastPeriodStart).inDays + 1;
|
||||
// Estimate phase based on standard 28 day. User might want actual phase logic.
|
||||
// Reusing CycleService logic would be best but requires instantiating it with all data.
|
||||
|
||||
String phase = 'Follicular';
|
||||
if (day > 14) phase = 'Luteal'; // Very rough approximation
|
||||
if (day == 14) phase = 'Ovulation';
|
||||
|
||||
summary.add('Day $day ($phase)');
|
||||
}
|
||||
|
||||
if (entry.mood != null) {
|
||||
summary.add('Mood: ${entry.mood!.label}');
|
||||
}
|
||||
@@ -135,12 +171,12 @@ class CycleHistoryScreen extends ConsumerWidget {
|
||||
summary.add('${entry.symptomCount} symptom(s)');
|
||||
}
|
||||
if (entry.notes != null && entry.notes!.isNotEmpty) {
|
||||
summary.add('Note');
|
||||
summary.add('Note: "${entry.notes}"');
|
||||
}
|
||||
if (summary.isEmpty) {
|
||||
return 'No specific data logged.';
|
||||
}
|
||||
return summary.join(' • ');
|
||||
return summary.join('\n'); // Use newline for better readability with notes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user