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:
@@ -9,6 +9,8 @@ import '../../widgets/scripture_card.dart';
|
||||
import '../../models/user_profile.dart';
|
||||
import '../../models/teaching_plan.dart';
|
||||
import '../../providers/scripture_provider.dart'; // Import the new provider
|
||||
import '../prayer/prayer_request_screen.dart';
|
||||
import '../settings/sharing_settings_screen.dart';
|
||||
|
||||
class DevotionalScreen extends ConsumerStatefulWidget {
|
||||
const DevotionalScreen({super.key});
|
||||
@@ -372,9 +374,16 @@ class _DevotionalScreenState extends ConsumerState<DevotionalScreen> {
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.edit_note),
|
||||
label: const Text('Journal'),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const PrayerRequestScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.spa_outlined),
|
||||
label: const Text('Prayer Requests'),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -623,7 +632,14 @@ class _DevotionalScreenState extends ConsumerState<DevotionalScreen> {
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _showShareDialog(context),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SharingSettingsScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.link, size: 18),
|
||||
label: const Text('Connect with Husband'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
@@ -636,70 +652,4 @@ class _DevotionalScreenState extends ConsumerState<DevotionalScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showShareDialog(BuildContext context) {
|
||||
// Generate a simple pairing code (in a real app, this would be stored/validated)
|
||||
final userProfile = ref.read(userProfileProvider);
|
||||
final pairingCode =
|
||||
userProfile?.id.substring(0, 6).toUpperCase() ?? 'ABC123';
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.share_outlined, color: AppColors.navyBlue),
|
||||
SizedBox(width: 8),
|
||||
Text('Share with Husband'),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Share this code with your husband so he can connect to your cycle data:',
|
||||
style:
|
||||
GoogleFonts.outfit(fontSize: 14, color: AppColors.warmGray),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.navyBlue.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.navyBlue.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: SelectableText(
|
||||
pairingCode,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 4,
|
||||
color: AppColors.navyBlue,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'He can enter this in his app under Settings > Connect with Wife.',
|
||||
style:
|
||||
GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Done'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -9,6 +9,9 @@ import '../../services/notification_service.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../widgets/protected_wrapper.dart';
|
||||
|
||||
// Global flag to track if the check-in dialog has been shown this session
|
||||
bool _hasShownCheckInSession = false;
|
||||
|
||||
class PadTrackerScreen extends ConsumerStatefulWidget {
|
||||
final FlowIntensity? initialFlow;
|
||||
final bool isSpotting;
|
||||
@@ -81,7 +84,15 @@ class _PadTrackerScreenState extends ConsumerState<PadTrackerScreen> {
|
||||
lastChange.month == now.month &&
|
||||
lastChange.day == now.day;
|
||||
|
||||
// Check if we already showed it this session
|
||||
if (_hasShownCheckInSession) {
|
||||
debugPrint('_checkInitialPrompt: Already shown this session. Skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!changedToday) {
|
||||
_hasShownCheckInSession = true; // Mark as shown immediately
|
||||
|
||||
final result = await showDialog<_PadLogResult>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -91,7 +102,7 @@ class _PadTrackerScreenState extends ConsumerState<PadTrackerScreen> {
|
||||
if (result != null) {
|
||||
if (result.skipped) return;
|
||||
|
||||
_finalizeLog(
|
||||
await _finalizeLog(
|
||||
result.time,
|
||||
result.flow,
|
||||
supply: result.supply,
|
||||
@@ -1162,7 +1173,7 @@ class _PadCheckInDialogState extends ConsumerState<_PadCheckInDialog> {
|
||||
padding: const EdgeInsets.only(left: 16.0),
|
||||
child: DropdownButtonFormField<PadType>(
|
||||
isExpanded: true,
|
||||
value: _borrowedType,
|
||||
initialValue: _borrowedType,
|
||||
items: PadType.values.map((t) {
|
||||
return DropdownMenuItem(
|
||||
value: t,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'dart:async'; // Add this import for Timer
|
||||
// import 'dart:convert'; // For encoding/decoding // Removed unused import to fix lint
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart'; // For Clipboard
|
||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
@@ -8,6 +11,7 @@ import '../husband/husband_home_screen.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../../services/sync_service.dart';
|
||||
|
||||
class OnboardingScreen extends ConsumerStatefulWidget {
|
||||
const OnboardingScreen({super.key});
|
||||
@@ -34,9 +38,17 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
bool _isPadTrackingEnabled = false;
|
||||
|
||||
// Connection options
|
||||
late String _userId;
|
||||
String? _partnerId;
|
||||
bool _useExampleData = false;
|
||||
bool _skipPartnerConnection = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_userId = const Uuid().v4();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
@@ -52,10 +64,34 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
|
||||
int nextPage = _currentPage + 1;
|
||||
|
||||
// Early Server Registration (After Name/Role selection)
|
||||
if (_currentPage == 1) {
|
||||
// Don't await this, let it happen in background to keep UI snappy?
|
||||
// Actually, await it to ensure ID is valid before they reach "Connect"?
|
||||
// "Connect" is Page 2 for Husband.
|
||||
// So yes, we should probably await or just fire and hope response is fast.
|
||||
// But _nextPage is async.
|
||||
|
||||
// Let's fire and forget, but maybe add a small delay or ensure it happens.
|
||||
// Since it's local network often, it should be fast.
|
||||
_registerEarly();
|
||||
}
|
||||
|
||||
// Logic for skipping pages
|
||||
// Logic for skipping pages
|
||||
if (_role == UserRole.husband) {
|
||||
if (_currentPage == 2) {
|
||||
// Finish after connect page
|
||||
if (!_useExampleData) {
|
||||
final id = await _showConnectDialog();
|
||||
if (id != null && id.isNotEmpty) {
|
||||
setState(() => _partnerId = id);
|
||||
} else if (id == null) {
|
||||
// Cancelled
|
||||
if (mounted) setState(() => _isNavigating = false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await _completeOnboarding();
|
||||
return;
|
||||
}
|
||||
@@ -74,6 +110,9 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
}
|
||||
if (_currentPage == 5) {
|
||||
// Finish after connect page (married wife)
|
||||
if (!_skipPartnerConnection) {
|
||||
await _showInviteDialog();
|
||||
}
|
||||
await _completeOnboarding();
|
||||
return;
|
||||
}
|
||||
@@ -125,14 +164,56 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _registerEarly() async {
|
||||
// Register the user on the server early so partner can link to them
|
||||
// immediately.
|
||||
try {
|
||||
final userDetails = {
|
||||
'name': _name,
|
||||
'role': _role.name,
|
||||
'partnerId': null, // No partner yet
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
};
|
||||
|
||||
await SyncService().pushSyncData(
|
||||
userId: _userId,
|
||||
entries: [],
|
||||
teachingPlans: [],
|
||||
prayerRequests: [],
|
||||
userDetails: userDetails,
|
||||
);
|
||||
debugPrint('Early registration successful for $_name');
|
||||
} catch (e) {
|
||||
debugPrint('Early registration failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _completeOnboarding() async {
|
||||
// 1. Check for Server-Linked Partner (Auto-Discovery)
|
||||
// If the husband linked to us while we were finishing the form,
|
||||
// the server will have the partnerId.
|
||||
try {
|
||||
final syncData = await SyncService().pullSyncData(_userId);
|
||||
if (syncData.containsKey('userProfile')) {
|
||||
final serverProfile = syncData['userProfile'] as Map<String, dynamic>;
|
||||
if (serverProfile['partnerId'] != null) {
|
||||
_partnerId = serverProfile['partnerId'];
|
||||
debugPrint('Auto-discovered partner: $_partnerId');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Error checking for partner link: $e');
|
||||
}
|
||||
|
||||
// 2. Create User Profile
|
||||
final userProfile = UserProfile(
|
||||
id: const Uuid().v4(),
|
||||
id: _userId,
|
||||
name: _name,
|
||||
role: _role,
|
||||
relationshipStatus: _role == UserRole.husband
|
||||
? RelationshipStatus.married
|
||||
: _relationshipStatus,
|
||||
partnerId: _partnerId,
|
||||
fertilityGoal: (_role == UserRole.wife &&
|
||||
_relationshipStatus == RelationshipStatus.married)
|
||||
? _fertilityGoal
|
||||
@@ -141,14 +222,39 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
lastPeriodStartDate: _lastPeriodStart,
|
||||
isIrregularCycle: _isIrregularCycle,
|
||||
hasCompletedOnboarding: true,
|
||||
// useExampleData: Removed
|
||||
isPadTrackingEnabled: _isPadTrackingEnabled,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
// 3. Save Profile (triggers local save)
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(userProfile);
|
||||
|
||||
// 4. Force Final Sync (Push everything including completed status)
|
||||
// Note: CycleEntriesNotifier handles data sync, but we want to ensure
|
||||
// profile is consistent. The Provider doesn't push profile changes automatically yet,
|
||||
// so we do it manually or rely on the next data change.
|
||||
// For safety, let's just push one last time or let the Home Screen handle it.
|
||||
// But since we just updated the profile, we should sync it.
|
||||
try {
|
||||
final userDetails = {
|
||||
'name': userProfile.name,
|
||||
'role': userProfile.role.name,
|
||||
'partnerId': userProfile.partnerId,
|
||||
'createdAt': userProfile.createdAt.toIso8601String(),
|
||||
};
|
||||
|
||||
await SyncService().pushSyncData(
|
||||
userId: _userId,
|
||||
entries: [],
|
||||
teachingPlans: [],
|
||||
prayerRequests: [],
|
||||
userDetails: userDetails,
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Final onboarding sync failed: $e');
|
||||
}
|
||||
|
||||
// Generate example data if requested - REMOVED
|
||||
/*
|
||||
if (_useExampleData) {
|
||||
@@ -456,7 +562,7 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: activeColor,
|
||||
),
|
||||
child: Text(isHusband ? 'Finish Setup' : 'Continue'),
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1140,4 +1246,260 @@ class _OnboardingScreenState extends ConsumerState<OnboardingScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _showConnectDialog() async {
|
||||
// Ensure we exist before connecting
|
||||
await _ensureServerRegistration();
|
||||
|
||||
final controller = TextEditingController();
|
||||
String? error;
|
||||
bool isLoading = false;
|
||||
|
||||
// State for the dialog: 'input', 'confirm'
|
||||
String step = 'input';
|
||||
String? partnerName;
|
||||
String? partnerRole;
|
||||
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
if (step == 'confirm') {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Connection'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Found Partner: $partnerName'),
|
||||
if (partnerRole != null) Text('Role: $partnerRole'),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Do you want to connect with this user?'),
|
||||
if (isLoading) ...[
|
||||
const SizedBox(height: 16),
|
||||
const CircularProgressIndicator(),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (!isLoading)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
step = 'input';
|
||||
error = null;
|
||||
});
|
||||
},
|
||||
child: const Text('Back'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () async {
|
||||
setState(() => isLoading = true);
|
||||
try {
|
||||
// Final Link
|
||||
final input = controller.text.trim();
|
||||
await SyncService().verifyPartnerId(_userId, input);
|
||||
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text('Connected to $partnerName!')),
|
||||
);
|
||||
Navigator.pop(context, input);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
error = 'Connection Request Failed';
|
||||
step = 'input';
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Confirm & Link'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Connect with Partner'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Enter your partner\'s User ID:'),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
hintText: 'Paste ID here',
|
||||
errorText: error,
|
||||
),
|
||||
enabled: !isLoading,
|
||||
),
|
||||
if (isLoading) ...[
|
||||
const SizedBox(height: 16),
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Searching...'),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (!isLoading)
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () async {
|
||||
final input = controller.text.trim();
|
||||
if (input.isEmpty) return;
|
||||
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
// Preview First
|
||||
final result =
|
||||
await SyncService().previewPartnerId(input);
|
||||
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
partnerName = result['partnerName'];
|
||||
partnerRole = result['partnerRole'];
|
||||
step = 'confirm';
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
// Show actual error for debugging
|
||||
error = e
|
||||
.toString()
|
||||
.replaceAll('Exception:', '')
|
||||
.trim();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Find Partner'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _ensureServerRegistration() async {
|
||||
await _registerEarly();
|
||||
}
|
||||
|
||||
Future<void> _showInviteDialog() async {
|
||||
// 1. Ensure we are actually registered so they can find us
|
||||
await _ensureServerRegistration();
|
||||
|
||||
Timer? pollTimer;
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
// Poll for connection
|
||||
if (pollTimer == null) {
|
||||
pollTimer =
|
||||
Timer.periodic(const Duration(seconds: 3), (timer) async {
|
||||
if (!mounted) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we are connected yet
|
||||
try {
|
||||
final result = await SyncService().pullSyncData(_userId);
|
||||
if (result.containsKey('userProfile')) {
|
||||
final profile = result['userProfile'];
|
||||
final partnerId = profile['partnerId'];
|
||||
if (partnerId != null) {
|
||||
// SUCCESS!
|
||||
timer.cancel();
|
||||
if (context.mounted) {
|
||||
// We could also fetch partner name here if needed,
|
||||
// but for now we just know we are linked.
|
||||
// Or pull again to get teaching plans etc if they synced.
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Husband Connected Successfully!')),
|
||||
);
|
||||
Navigator.pop(context); // Close dialog
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Poll error: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Invite Partner'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Share this code with your partner:'),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SelectableText(
|
||||
_userId,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: _userId));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Copied to clipboard!')),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Waiting for him to connect...'),
|
||||
const SizedBox(height: 8),
|
||||
const LinearProgressIndicator(),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
pollTimer?.cancel();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Cancel / Done'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
pollTimer?.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
188
lib/screens/prayer/prayer_request_screen.dart
Normal file
188
lib/screens/prayer/prayer_request_screen.dart
Normal file
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../providers/prayer_provider.dart';
|
||||
import '../../models/prayer_request.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
class PrayerRequestScreen extends ConsumerWidget {
|
||||
const PrayerRequestScreen({super.key});
|
||||
|
||||
void _showAddDialog(BuildContext context, WidgetRef ref) {
|
||||
final controller = TextEditingController();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('New Prayer Request',
|
||||
style: GoogleFonts.outfit(fontWeight: FontWeight.bold)),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'What can we pray for?',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
maxLines: 3,
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (controller.text.isNotEmpty) {
|
||||
ref
|
||||
.read(prayerRequestsProvider.notifier)
|
||||
.addRequest(controller.text.trim());
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: const Text('Add'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final requests = ref.watch(prayerRequestsProvider);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// Separate active and answered
|
||||
final active = requests.where((r) => !r.isAnswered).toList();
|
||||
final answered = requests.where((r) => r.isAnswered).toList();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Prayer Requests',
|
||||
style: GoogleFonts.outfit(fontWeight: FontWeight.bold)),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: requests.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.spa_outlined,
|
||||
size: 64, color: theme.disabledColor),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No prayer requests yet.',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
color: theme.textTheme.bodyMedium?.color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _showAddDialog(context, ref),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add First Request'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (active.isNotEmpty) ...[
|
||||
Text('Active Requests',
|
||||
style: GoogleFonts.outfit(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 18,
|
||||
color: AppColors.charcoal)),
|
||||
const SizedBox(height: 8),
|
||||
...active.map((req) => _PrayerCard(request: req)),
|
||||
],
|
||||
if (active.isNotEmpty && answered.isNotEmpty)
|
||||
const Divider(height: 32),
|
||||
if (answered.isNotEmpty) ...[
|
||||
Text('Answered Prayers',
|
||||
style: GoogleFonts.outfit(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 18,
|
||||
color: AppColors.sageGreen)),
|
||||
const SizedBox(height: 8),
|
||||
...answered.map((req) => _PrayerCard(request: req)),
|
||||
],
|
||||
],
|
||||
),
|
||||
floatingActionButton: requests.isNotEmpty
|
||||
? FloatingActionButton(
|
||||
onPressed: () => _showAddDialog(context, ref),
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PrayerCard extends ConsumerWidget {
|
||||
final PrayerRequest request;
|
||||
const _PrayerCard({required this.request});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
final isAnswered = request.isAnswered;
|
||||
final dateStr = DateFormat('MMM d, yyyy').format(request.createdAt);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
title: Text(
|
||||
request.request,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration:
|
||||
isAnswered ? TextDecoration.lineThrough : TextDecoration.none,
|
||||
color: isAnswered
|
||||
? theme.disabledColor
|
||||
: theme.textTheme.bodyLarge?.color,
|
||||
),
|
||||
),
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
dateStr,
|
||||
style: GoogleFonts.outfit(fontSize: 12, color: theme.disabledColor),
|
||||
),
|
||||
),
|
||||
trailing: Checkbox(
|
||||
value: isAnswered,
|
||||
activeColor: AppColors.sageGreen,
|
||||
onChanged: (val) {
|
||||
ref.read(prayerRequestsProvider.notifier).toggleAnswered(request);
|
||||
},
|
||||
),
|
||||
onLongPress: () async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete Request?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Cancel')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Delete',
|
||||
style: TextStyle(color: Colors.red))),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirm == true) {
|
||||
ref.read(prayerRequestsProvider.notifier).deleteRequest(request.id);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,163 +1,238 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../services/sync_service.dart';
|
||||
|
||||
class SharingSettingsScreen extends ConsumerWidget {
|
||||
class SharingSettingsScreen extends ConsumerStatefulWidget {
|
||||
const SharingSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final userProfile = ref.watch(userProfileProvider);
|
||||
ConsumerState<SharingSettingsScreen> createState() =>
|
||||
_SharingSettingsScreenState();
|
||||
}
|
||||
|
||||
if (userProfile == null) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Sharing Settings'),
|
||||
),
|
||||
body: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
class _SharingSettingsScreenState extends ConsumerState<SharingSettingsScreen> {
|
||||
final _partnerIdController = TextEditingController();
|
||||
bool _isLoading = false;
|
||||
String? _errorText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null && user.partnerId != null) {
|
||||
_partnerIdController.text = user.partnerId!;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_partnerIdController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _savePartnerId() async {
|
||||
final input = _partnerIdController.text.trim();
|
||||
if (input.isEmpty) return;
|
||||
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null) {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_errorText = null;
|
||||
});
|
||||
|
||||
try {
|
||||
// 1. Preview first
|
||||
final result = await SyncService().previewPartnerId(input);
|
||||
final partnerName = result['partnerName'];
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// 2. Show Confirmation Dialog
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Confirm Partner'),
|
||||
content: Text(
|
||||
'Found partner: $partnerName.\n\nDo you want to link with them?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Confirm Link'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm != true) {
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Perform Link
|
||||
final verifyResult =
|
||||
await SyncService().verifyPartnerId(user.id, input);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
user.copyWith(
|
||||
partnerId: input,
|
||||
partnerName: verifyResult['partnerName'],
|
||||
),
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Connected to ${verifyResult['partnerName']}!')),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_errorText = e.toString().replaceAll('Exception:', '').trim();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = ref.watch(userProfileProvider);
|
||||
if (user == null) return const Scaffold();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Sharing Settings'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Sharing & Partner')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.link),
|
||||
title: const Text('Link with Husband'),
|
||||
subtitle: Text(userProfile.partnerName != null
|
||||
? 'Linked to ${userProfile.partnerName}'
|
||||
: 'Not linked'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showShareDialog(context, ref),
|
||||
),
|
||||
_buildPartnerSection(user),
|
||||
const Divider(),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Moods'),
|
||||
value: userProfile.shareMoods,
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(userProfile.copyWith(shareMoods: value));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Symptoms'),
|
||||
value: userProfile.shareSymptoms,
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(userProfile.copyWith(shareSymptoms: value));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Cravings'),
|
||||
value: userProfile.shareCravings,
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(userProfile.copyWith(shareCravings: value));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Energy Levels'),
|
||||
value: userProfile.shareEnergyLevels,
|
||||
onChanged: (value) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(
|
||||
userProfile.copyWith(shareEnergyLevels: value));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Sleep Data'),
|
||||
value: userProfile.shareSleep,
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(userProfile.copyWith(shareSleep: value));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Intimacy Details'),
|
||||
value: userProfile.shareIntimacy,
|
||||
onChanged: (value) {
|
||||
ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.updateProfile(userProfile.copyWith(shareIntimacy: value));
|
||||
},
|
||||
),
|
||||
_buildSharingToggles(user),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showShareDialog(BuildContext context, WidgetRef ref) {
|
||||
// Generate a simple pairing code
|
||||
final userProfile = ref.read(userProfileProvider);
|
||||
final pairingCode =
|
||||
userProfile?.id.substring(0, 6).toUpperCase() ?? 'ABC123';
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
children: [
|
||||
Icon(Icons.share_outlined, color: AppColors.navyBlue),
|
||||
SizedBox(width: 8),
|
||||
Text('Share with Husband'),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Share this code with your husband so he can connect to your cycle data:',
|
||||
style:
|
||||
GoogleFonts.outfit(fontSize: 14, color: AppColors.warmGray),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.navyBlue.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.navyBlue.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: SelectableText(
|
||||
pairingCode,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 4,
|
||||
color: AppColors.navyBlue,
|
||||
Widget _buildPartnerSection(user) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Partner Connection',
|
||||
style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 16),
|
||||
// My ID
|
||||
Text('My ID (Share this with your partner):',
|
||||
style: Theme.of(context).textTheme.bodySmall),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SelectableText(
|
||||
user.id,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'He can enter this in his app under Settings > Connect with Wife.',
|
||||
style:
|
||||
GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.navyBlue,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: const Text('Done'),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: user.id));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('ID copied to clipboard')),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Partner ID Input
|
||||
TextField(
|
||||
controller: _partnerIdController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Enter Partner ID',
|
||||
border: const OutlineInputBorder(),
|
||||
hintText: 'Paste partner ID here',
|
||||
errorText: _errorText,
|
||||
),
|
||||
enabled: !_isLoading,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (_isLoading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
else
|
||||
ElevatedButton(
|
||||
onPressed: _savePartnerId,
|
||||
child: const Text('Link Partner'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSharingToggles(user) {
|
||||
final notifier = ref.read(userProfileProvider.notifier);
|
||||
final isPadTrackingEnabled = user.isPadTrackingEnabled ?? false;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text('What to Share',
|
||||
style: Theme.of(context).textTheme.titleMedium),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Moods'),
|
||||
value: user.shareMoods,
|
||||
onChanged: (val) =>
|
||||
notifier.updateProfile(user.copyWith(shareMoods: val)),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Symptoms'),
|
||||
value: user.shareSymptoms,
|
||||
onChanged: (val) =>
|
||||
notifier.updateProfile(user.copyWith(shareSymptoms: val)),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Energy Levels'),
|
||||
value: user.shareEnergyLevels,
|
||||
onChanged: (val) =>
|
||||
notifier.updateProfile(user.copyWith(shareEnergyLevels: val)),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Pad Supplies'),
|
||||
subtitle: !isPadTrackingEnabled
|
||||
? const Text('Enable Pad Tracking to share supplies')
|
||||
: null,
|
||||
value: isPadTrackingEnabled && (user.sharePadSupplies ?? true),
|
||||
onChanged: isPadTrackingEnabled
|
||||
? (val) =>
|
||||
notifier.updateProfile(user.copyWith(sharePadSupplies: val))
|
||||
: null,
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Share Intimacy'),
|
||||
subtitle: const Text('Always shared with your husband'),
|
||||
value: true, // Always true
|
||||
onChanged: null, // Disabled - always on
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user