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:
@@ -7,8 +7,8 @@ import '../../models/teaching_plan.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../services/bible_xml_parser.dart';
|
||||
import '../../services/mock_data_service.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../settings/sharing_settings_screen.dart';
|
||||
|
||||
class HusbandDevotionalScreen extends ConsumerStatefulWidget {
|
||||
const HusbandDevotionalScreen({super.key});
|
||||
@@ -499,7 +499,7 @@ class _HusbandDevotionalScreenState
|
||||
BuildContext context, WidgetRef ref, UserProfile? user) {
|
||||
// Check if connected (partnerName is set)
|
||||
final isConnected =
|
||||
user?.partnerName != null && (user?.partnerName?.isNotEmpty ?? false);
|
||||
user?.partnerId != null && (user?.partnerId?.isNotEmpty ?? false);
|
||||
|
||||
// Get today's cycle entry to check for prayer requests
|
||||
final entries = ref.watch(cycleEntriesProvider);
|
||||
@@ -558,7 +558,12 @@ class _HusbandDevotionalScreenState
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => _showConnectDialog(context, ref),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const SharingSettingsScreen(),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.link),
|
||||
label: const Text('Connect with Wife'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
@@ -654,94 +659,4 @@ class _HusbandDevotionalScreenState
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showConnectDialog(BuildContext context, WidgetRef ref) {
|
||||
final codeController = TextEditingController();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.link, color: AppColors.navyBlue),
|
||||
SizedBox(width: 8),
|
||||
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: AppColors.warmGray),
|
||||
),
|
||||
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 Devotional screen under "Share with Husband".',
|
||||
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);
|
||||
|
||||
if (code.isNotEmpty) {
|
||||
// Simulate connection with mock data
|
||||
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(
|
||||
partnerName: mockWife.name,
|
||||
averageCycleLength: mockWife.averageCycleLength,
|
||||
averagePeriodLength: mockWife.averagePeriodLength,
|
||||
lastPeriodStartDate: mockWife.lastPeriodStartDate,
|
||||
);
|
||||
await ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(updatedProfile);
|
||||
}
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Connected with wife! 💑'),
|
||||
backgroundColor: AppColors.sageGreen,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Connect'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user