Implement husband-wife connection dialogue and theme support for learn articles

This commit is contained in:
2026-01-05 17:09:15 -06:00
parent 02d25d0cc7
commit 96655f9a74
36 changed files with 3849 additions and 819 deletions

View File

@@ -9,6 +9,8 @@ import '../../providers/user_provider.dart';
import '../../services/cycle_service.dart';
import '../../theme/app_theme.dart';
import '../log/log_screen.dart';
import 'package:uuid/uuid.dart';
import '../../widgets/protected_wrapper.dart';
class CalendarScreen extends ConsumerStatefulWidget {
final bool readOnly;
@@ -22,38 +24,63 @@ class CalendarScreen extends ConsumerStatefulWidget {
ConsumerState<CalendarScreen> createState() => _CalendarScreenState();
}
enum PredictionMode { short, regular, long }
class _CalendarScreenState extends ConsumerState<CalendarScreen> {
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay;
CalendarFormat _calendarFormat = CalendarFormat.month;
PredictionMode _predictionMode = PredictionMode.regular;
@override
Widget build(BuildContext context) {
final entries = ref.watch(cycleEntriesProvider);
final user = ref.watch(userProfileProvider);
final cycleLength = user?.averageCycleLength ?? 28;
final isIrregular = user?.isIrregularCycle ?? false;
int cycleLength = user?.averageCycleLength ?? 28;
if (isIrregular) {
if (_predictionMode == PredictionMode.short) {
cycleLength = user?.minCycleLength ?? 25;
} else if (_predictionMode == PredictionMode.long) {
cycleLength = user?.maxCycleLength ?? 35;
}
}
final lastPeriodStart = user?.lastPeriodStartDate;
return SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
return ProtectedContentWrapper(
title: 'Calendar',
isProtected: user?.isCalendarProtected ?? false,
userProfile: user,
child: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
// Header
Padding(
padding: const EdgeInsets.all(20),
child: Row(
child: Column(
children: [
Expanded(
child: Text(
'Calendar',
style: GoogleFonts.outfit(
fontSize: 28,
fontWeight: FontWeight.w600,
color: AppColors.charcoal,
Row(
children: [
Expanded(
child: Text(
'Calendar',
style: GoogleFonts.outfit(
fontSize: 28,
fontWeight: FontWeight.w600,
color: AppColors.charcoal,
),
),
),
),
_buildLegendButton(),
],
),
_buildLegendButton(),
if (isIrregular) ...[
const SizedBox(height: 16),
_buildPredictionToggle(),
],
],
),
),
@@ -242,13 +269,64 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
// Day Info (No longer Expanded)
_buildDayInfo(
_selectedDay!, lastPeriodStart, cycleLength, entries),
_selectedDay!, lastPeriodStart, cycleLength, entries, user),
const SizedBox(height: 40), // Bottom padding
],
],
),
),
));
}
Widget _buildPredictionToggle() {
return Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: AppColors.lightGray.withOpacity(0.5),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
_buildToggleItem(PredictionMode.short, 'Short (-)', AppColors.menstrualPhase),
_buildToggleItem(PredictionMode.regular, 'Regular', AppColors.sageGreen),
_buildToggleItem(PredictionMode.long, 'Long (+)', AppColors.lutealPhase),
],
),
);
}
Widget _buildToggleItem(PredictionMode mode, String label, Color color) {
final isSelected = _predictionMode == mode;
return Expanded(
child: GestureDetector(
onTap: () => setState(() => _predictionMode = mode),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: isSelected ? Colors.white : Colors.transparent,
borderRadius: BorderRadius.circular(8),
boxShadow: isSelected
? [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 4,
offset: const Offset(0, 2),
)
]
: null,
),
child: Text(
label,
textAlign: TextAlign.center,
style: GoogleFonts.outfit(
fontSize: 13,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
color: isSelected ? color : AppColors.warmGray,
),
),
),
),
);
}
@@ -338,7 +416,7 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
}
Widget _buildDayInfo(DateTime date, DateTime? lastPeriodStart, int cycleLength,
List<CycleEntry> entries) {
List<CycleEntry> entries, UserProfile? user) {
final phase = _getPhaseForDate(date, lastPeriodStart, cycleLength);
final entry = _getEntryForDate(date, entries);
@@ -401,15 +479,21 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
),
),
),
if (entry == null)
if (entry == null) ...[
Text(
phase?.description ?? 'No data for this date',
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: AppColors.warmGray),
)
else ...[
),
if (user?.isPadTrackingEnabled == true &&
phase != CyclePhase.menstrual &&
(user?.padSupplies?.any((s) => s.type == PadType.pantyLiner) ?? false)) ...[
const SizedBox(height: 16),
_buildPantylinerPrompt(date, null),
],
] else ...[
// Period Detail
if (entry.isPeriodDay)
_buildDetailRow(Icons.water_drop, 'Period Day',
@@ -436,6 +520,17 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
// Contextual Recommendation
_buildRecommendation(entry),
// Pad Tracking Specifics (Not shared with husband)
if (user?.isPadTrackingEnabled == true) ...[
const SizedBox(height: 16),
if (entry.usedPantyliner)
_buildDetailRow(Icons.layers_outlined, 'Supplies Used', AppColors.menstrualPhase,
value: '${entry.pantylinerCount}'),
if (!entry.usedPantyliner && !entry.isPeriodDay)
_buildPantylinerPrompt(date, entry),
],
// Notes
if (entry.notes?.isNotEmpty == true)
Padding(
@@ -455,6 +550,12 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
),
),
],
if (user?.isPadTrackingEnabled == true) ...[
const SizedBox(height: 16),
_buildManualSupplyEntryButton(date),
],
const SizedBox(height: 24),
// Action Buttons
@@ -496,6 +597,71 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> {
);
}
Widget _buildPantylinerPrompt(DateTime date, CycleEntry? entry) {
return Container(
margin: const EdgeInsets.only(top: 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: AppColors.menstrualPhase.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.menstrualPhase.withOpacity(0.2)),
),
child: Row(
children: [
const Icon(Icons.help_outline, color: AppColors.menstrualPhase, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
'Did you use pantyliners today?',
style: GoogleFonts.outfit(fontSize: 14, color: AppColors.charcoal),
),
),
TextButton(
onPressed: () {
if (entry != null) {
ref.read(cycleEntriesProvider.notifier).updateEntry(
entry.copyWith(usedPantyliner: true, pantylinerCount: 1),
);
} else {
final newEntry = CycleEntry(
id: const Uuid().v4(),
date: date,
usedPantyliner: true,
pantylinerCount: 1,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
ref.read(cycleEntriesProvider.notifier).addEntry(newEntry);
}
},
child: Text('Yes', style: GoogleFonts.outfit(color: AppColors.menstrualPhase, fontWeight: FontWeight.bold)),
),
],
),
);
}
Widget _buildManualSupplyEntryButton(DateTime date) {
return SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () {
// Open a simplified version of the supply management or just log a change
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Supply usage recorded manually.')),
);
},
icon: const Icon(Icons.add_shopping_cart, size: 18),
label: const Text('Manual Supply Entry'),
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.menstrualPhase,
side: const BorderSide(color: AppColors.menstrualPhase),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
),
);
}
Widget _buildRecommendation(CycleEntry entry) {
final scripture = ScriptureDatabase().getRecommendedScripture(entry);
if (scripture == null) return const SizedBox.shrink();