Refactor: Implement multi-item inventory for Pad Tracker and dynamic navigation
This commit is contained in:
@@ -35,186 +35,219 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
|
||||
final lastPeriodStart = user?.lastPeriodStartDate;
|
||||
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Calendar',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.charcoal,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Calendar',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.charcoal,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildLegendButton(),
|
||||
],
|
||||
_buildLegendButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Calendar
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.charcoal.withOpacity(0.05),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDay: DateTime.now().add(const Duration(days: 365)),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
onFormatChanged: (format) {
|
||||
setState(() => _calendarFormat = format);
|
||||
},
|
||||
onPageChanged: (focusedDay) {
|
||||
_focusedDay = focusedDay;
|
||||
},
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
defaultTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
color: AppColors.charcoal,
|
||||
),
|
||||
weekendTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
color: AppColors.charcoal,
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.sageGreen.withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
todayTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.sageGreen,
|
||||
),
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.sageGreen,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
selectedTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
// Calendar
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: false,
|
||||
titleCentered: true,
|
||||
titleTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.charcoal,
|
||||
),
|
||||
leftChevronIcon: Icon(
|
||||
Icons.chevron_left,
|
||||
color: AppColors.warmGray,
|
||||
),
|
||||
rightChevronIcon: Icon(
|
||||
Icons.chevron_right,
|
||||
color: AppColors.warmGray,
|
||||
),
|
||||
),
|
||||
daysOfWeekStyle: DaysOfWeekStyle(
|
||||
weekdayStyle: GoogleFonts.outfit(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.warmGray,
|
||||
),
|
||||
weekendStyle: GoogleFonts.outfit(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.warmGray,
|
||||
),
|
||||
),
|
||||
calendarBuilders: CalendarBuilders(
|
||||
markerBuilder: (context, date, events) {
|
||||
final entry = _getEntryForDate(date, entries);
|
||||
|
||||
if (entry == null) {
|
||||
final phase =
|
||||
_getPhaseForDate(date, lastPeriodStart, cycleLength);
|
||||
if (phase != null) {
|
||||
return Positioned(
|
||||
bottom: 1,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: _getPhaseColor(phase).withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we have an entry, show icons/markers
|
||||
return Positioned(
|
||||
bottom: 1,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (entry.isPeriodDay)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.menstrualPhase,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (entry.mood != null ||
|
||||
entry.energyLevel != 3 ||
|
||||
entry.hasSymptoms)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.softGold,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDay: DateTime.now().add(const Duration(days: 365)),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
onFormatChanged: (format) {
|
||||
setState(() => _calendarFormat = format);
|
||||
},
|
||||
onPageChanged: (focusedDay) {
|
||||
_focusedDay = focusedDay;
|
||||
},
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
defaultTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color ?? AppColors.charcoal,
|
||||
),
|
||||
weekendTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color ?? AppColors.charcoal,
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.sageGreen.withOpacity(0.3),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
todayTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.sageGreen,
|
||||
),
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.sageGreen,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
selectedTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: false,
|
||||
titleCentered: true,
|
||||
titleTextStyle: GoogleFonts.outfit(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Theme.of(context).textTheme.titleLarge?.color ?? AppColors.charcoal,
|
||||
),
|
||||
leftChevronIcon: Icon(
|
||||
Icons.chevron_left,
|
||||
color: Theme.of(context).iconTheme.color ?? AppColors.warmGray,
|
||||
),
|
||||
rightChevronIcon: Icon(
|
||||
Icons.chevron_right,
|
||||
color: Theme.of(context).iconTheme.color ?? AppColors.warmGray,
|
||||
),
|
||||
),
|
||||
daysOfWeekStyle: DaysOfWeekStyle(
|
||||
weekdayStyle: GoogleFonts.outfit(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).textTheme.bodySmall?.color ?? AppColors.warmGray,
|
||||
),
|
||||
weekendStyle: GoogleFonts.outfit(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).textTheme.bodySmall?.color ?? AppColors.warmGray,
|
||||
),
|
||||
),
|
||||
calendarBuilders: CalendarBuilders(
|
||||
defaultBuilder: (context, day, focusedDay) {
|
||||
return _buildCalendarDay(day, focusedDay, entries, lastPeriodStart, cycleLength, isSelected: false, isToday: false);
|
||||
},
|
||||
todayBuilder: (context, day, focusedDay) {
|
||||
return _buildCalendarDay(day, focusedDay, entries, lastPeriodStart, cycleLength, isToday: true);
|
||||
},
|
||||
selectedBuilder: (context, day, focusedDay) {
|
||||
return _buildCalendarDay(day, focusedDay, entries, lastPeriodStart, cycleLength, isSelected: true);
|
||||
},
|
||||
markerBuilder: (context, date, events) {
|
||||
final entry = _getEntryForDate(date, entries);
|
||||
|
||||
if (entry == null) {
|
||||
final phase =
|
||||
_getPhaseForDate(date, lastPeriodStart, cycleLength);
|
||||
if (phase != null) {
|
||||
return Positioned(
|
||||
bottom: 4,
|
||||
child: Container(
|
||||
width: 5,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(
|
||||
color: _getPhaseColor(phase),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we have an entry, show icons/markers
|
||||
return Positioned(
|
||||
bottom: 4,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (entry.isPeriodDay)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.menstrualPhase,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (entry.mood != null ||
|
||||
entry.energyLevel != 3 ||
|
||||
entry.hasSymptoms)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.softGold,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Selected Day Info
|
||||
if (_selectedDay != null)
|
||||
Expanded(
|
||||
child: _buildDayInfo(
|
||||
// Divider / Header for Day Info
|
||||
if (_selectedDay != null) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'Daily Log',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.warmGray,
|
||||
letterSpacing: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(child: Divider(color: AppColors.lightGray)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Day Info (No longer Expanded)
|
||||
_buildDayInfo(
|
||||
_selectedDay!, lastPeriodStart, cycleLength, entries),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 40), // Bottom padding
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -633,6 +666,71 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
|
||||
return entry?.isPeriodDay ?? false;
|
||||
}
|
||||
|
||||
Widget _buildCalendarDay(
|
||||
DateTime day,
|
||||
DateTime focusedDay,
|
||||
List<CycleEntry> entries,
|
||||
DateTime? lastPeriodStart,
|
||||
int cycleLength,
|
||||
{bool isSelected = false, bool isToday = false, bool isWeekend = false}) {
|
||||
final phase = _getPhaseForDate(day, lastPeriodStart, cycleLength);
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
// Determine the Day of Cycle
|
||||
int? doc;
|
||||
if (lastPeriodStart != null) {
|
||||
final diff = day.difference(lastPeriodStart).inDays;
|
||||
if (diff >= 0) {
|
||||
doc = (diff % cycleLength) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
final isOvulationDay = doc == 14;
|
||||
final isPeriodStart = doc == 1;
|
||||
|
||||
// Background decoration based on phase
|
||||
BoxDecoration? decoration;
|
||||
if (isSelected) {
|
||||
decoration = const BoxDecoration(
|
||||
color: AppColors.sageGreen,
|
||||
shape: BoxShape.circle,
|
||||
);
|
||||
} else if (isToday) {
|
||||
decoration = BoxDecoration(
|
||||
color: AppColors.sageGreen.withOpacity(0.2),
|
||||
shape: BoxShape.circle,
|
||||
);
|
||||
} else if (phase != null) {
|
||||
decoration = BoxDecoration(
|
||||
color: _getPhaseColor(phase).withOpacity(isDark ? 0.2 : 0.15),
|
||||
shape: BoxShape.circle,
|
||||
);
|
||||
}
|
||||
|
||||
// Text style
|
||||
TextStyle textStyle = GoogleFonts.outfit(
|
||||
fontSize: (isOvulationDay || isPeriodStart) ? 18 : 14,
|
||||
fontWeight: (isOvulationDay || isPeriodStart) ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected ? Colors.white : (isToday ? AppColors.sageGreen : (Theme.of(context).textTheme.bodyMedium?.color)),
|
||||
);
|
||||
|
||||
if (isOvulationDay) {
|
||||
textStyle = textStyle.copyWith(color: isSelected ? Colors.white : AppColors.ovulationPhase);
|
||||
} else if (isPeriodStart) {
|
||||
textStyle = textStyle.copyWith(color: isSelected ? Colors.white : AppColors.menstrualPhase);
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(4),
|
||||
alignment: Alignment.center,
|
||||
decoration: decoration,
|
||||
child: Text(
|
||||
'${day.day}',
|
||||
style: textStyle,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
CycleEntry? _getEntryForDate(DateTime date, List<CycleEntry> entries) {
|
||||
try {
|
||||
return entries.firstWhere(
|
||||
|
||||
Reference in New Issue
Block a user