feat: Add auto-sync, fix partner linking UI, update sharing settings

- Add 10-second periodic auto-sync to CycleEntriesNotifier
- Fix husband_devotional_screen: use partnerId for isConnected check, navigate to SharingSettingsScreen instead of legacy mock dialog
- Remove obsolete _showConnectDialog method and mock data import
- Update husband_settings_screen: show 'Partner Settings' with linked partner name when connected
- Add SharingSettingsScreen: Pad Supplies toggle (disabled when pad tracking off), Intimacy always enabled
- Add CORS OPTIONS handler to backend server
- Add _ensureServerRegistration for reliable partner linking
- Add copy button to Invite Partner dialog
- Dynamic base URL for web (uses window.location.hostname)
This commit is contained in:
2026-01-09 17:20:49 -06:00
parent d28898cb81
commit 1c2c56e9e2
21 changed files with 1690 additions and 493 deletions

View File

@@ -6,6 +6,7 @@ import '../../models/user_profile.dart';
import '../../providers/user_provider.dart';
import '../../services/mock_data_service.dart';
import 'husband_appearance_screen.dart';
import '../settings/sharing_settings_screen.dart';
class HusbandSettingsScreen extends ConsumerWidget {
const HusbandSettingsScreen({super.key});
@@ -139,155 +140,10 @@ class HusbandSettingsScreen extends ConsumerWidget {
);
}
void _showConnectDialog(BuildContext context, WidgetRef ref) {
final codeController = TextEditingController();
bool shareDevotional = true;
showDialog(
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setState) => AlertDialog(
title: Row(
children: [
Icon(Icons.link, color: Theme.of(context).colorScheme.primary),
const SizedBox(width: 8),
const Text('Connect with Wife'),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Enter the pairing code from your wife\'s app:',
style: GoogleFonts.outfit(
fontSize: 14,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
const SizedBox(height: 16),
TextField(
controller: codeController,
decoration: const InputDecoration(
hintText: 'e.g., ABC123',
border: OutlineInputBorder(),
),
textCapitalization: TextCapitalization.characters,
),
const SizedBox(height: 16),
Text(
'Your wife can find this code in her Settings under "Share with Husband".',
style: GoogleFonts.outfit(
fontSize: 12,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
const SizedBox(height: 24),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 24,
width: 24,
child: Checkbox(
value: shareDevotional,
onChanged: (val) =>
setState(() => shareDevotional = val ?? true),
activeColor: AppColors.sageGreen,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Share Devotional Plans',
style: GoogleFonts.outfit(
fontWeight: FontWeight.bold,
fontSize: 14,
color: AppColors.charcoal),
),
Text(
'Allow her to see the teaching plans you create.',
style: GoogleFonts.outfit(
fontSize: 12, color: AppColors.warmGray),
),
],
),
),
],
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () async {
final code = codeController.text.trim();
Navigator.pop(context);
// Update preference
final user = ref.read(userProfileProvider);
if (user != null) {
await ref.read(userProfileProvider.notifier).updateProfile(
user.copyWith(isDataShared: shareDevotional));
}
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Settings updated & Connected!'),
backgroundColor: AppColors.sageGreen,
),
);
}
if (code.isNotEmpty) {
// Load demo data as simulation
final mockService = MockDataService();
final entries = mockService.generateMockCycleEntries();
for (var entry in entries) {
await ref
.read(cycleEntriesProvider.notifier)
.addEntry(entry);
}
final mockWife = mockService.generateMockWifeProfile();
final currentProfile = ref.read(userProfileProvider);
if (currentProfile != null) {
final updatedProfile = currentProfile.copyWith(
isDataShared: shareDevotional,
partnerName: mockWife.name,
averageCycleLength: mockWife.averageCycleLength,
averagePeriodLength: mockWife.averagePeriodLength,
lastPeriodStartDate: mockWife.lastPeriodStartDate,
favoriteFoods: mockWife.favoriteFoods,
);
await ref
.read(userProfileProvider.notifier)
.updateProfile(updatedProfile);
}
}
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.navyBlue,
foregroundColor: Colors.white,
),
child: const Text('Connect'),
),
],
),
),
);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
// Theme aware colors
final user = ref.watch(userProfileProvider);
final cardColor =
Theme.of(context).cardTheme.color; // Using theme card color
final textColor = Theme.of(context).textTheme.bodyLarge?.color;
@@ -327,12 +183,29 @@ class HusbandSettingsScreen extends ConsumerWidget {
ListTile(
leading: Icon(Icons.link,
color: Theme.of(context).colorScheme.primary),
title: Text('Connect with Wife',
title: Text(
user?.partnerId != null
? 'Partner Settings'
: 'Connect with Wife',
style: GoogleFonts.outfit(
fontWeight: FontWeight.w500, color: textColor)),
subtitle: user?.partnerId != null &&
user?.partnerName != null
? Text('Linked with ${user!.partnerName}',
style: GoogleFonts.outfit(
fontSize: 12,
color: Theme.of(context).colorScheme.primary))
: null,
trailing: Icon(Icons.chevron_right,
color: Theme.of(context).disabledColor),
onTap: () => _showConnectDialog(context, ref),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SharingSettingsScreen(),
),
);
},
),
const Divider(height: 1),
ListTile(