Implement husband-wife connection dialogue and theme support for learn articles
This commit is contained in:
@@ -5,9 +5,16 @@ import 'package:collection/collection.dart';
|
||||
import '../../models/cycle_entry.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
|
||||
class CycleHistoryScreen extends ConsumerWidget {
|
||||
class CycleHistoryScreen extends ConsumerStatefulWidget {
|
||||
const CycleHistoryScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<CycleHistoryScreen> createState() => _CycleHistoryScreenState();
|
||||
}
|
||||
|
||||
class _CycleHistoryScreenState extends ConsumerState<CycleHistoryScreen> {
|
||||
bool _isUnlocked = false;
|
||||
|
||||
void _showDeleteAllDialog(BuildContext context, WidgetRef ref) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -42,9 +49,85 @@ class CycleHistoryScreen extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _authenticate() async {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user?.privacyPin == null) return;
|
||||
|
||||
final controller = TextEditingController();
|
||||
final pin = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Enter PIN'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
obscureText: true,
|
||||
maxLength: 4,
|
||||
style: const TextStyle(fontSize: 24, letterSpacing: 8),
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '....',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, controller.text),
|
||||
child: const Text('Unlock'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (pin == user!.privacyPin) {
|
||||
setState(() {
|
||||
_isUnlocked = true;
|
||||
});
|
||||
} else if (pin != null) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Incorrect PIN')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
Widget build(BuildContext context) {
|
||||
final entries = ref.watch(cycleEntriesProvider);
|
||||
final user = ref.watch(userProfileProvider);
|
||||
|
||||
// Privacy Check
|
||||
final isProtected = user?.isHistoryProtected ?? false;
|
||||
final hasPin = user?.privacyPin != null && user!.privacyPin!.isNotEmpty;
|
||||
final isLocked = isProtected && hasPin && !_isUnlocked;
|
||||
|
||||
if (isLocked) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Cycle History')),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.lock_outline, size: 64, color: Colors.grey),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'History is Protected',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _authenticate,
|
||||
icon: const Icon(Icons.key),
|
||||
label: const Text('Enter PIN to View'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final groupedEntries = groupBy(
|
||||
entries,
|
||||
|
||||
@@ -18,6 +18,7 @@ class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
|
||||
late TextEditingController _periodLengthController;
|
||||
DateTime? _lastPeriodStartDate;
|
||||
bool _isIrregularCycle = false;
|
||||
bool _isPadTrackingEnabled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -29,6 +30,7 @@ class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
|
||||
text: userProfile?.averagePeriodLength.toString() ?? '5');
|
||||
_lastPeriodStartDate = userProfile?.lastPeriodStartDate;
|
||||
_isIrregularCycle = userProfile?.isIrregularCycle ?? false;
|
||||
_isPadTrackingEnabled = userProfile?.isPadTrackingEnabled ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -47,6 +49,7 @@ class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
|
||||
averagePeriodLength: int.tryParse(_periodLengthController.text) ?? userProfile.averagePeriodLength,
|
||||
lastPeriodStartDate: _lastPeriodStartDate,
|
||||
isIrregularCycle: _isIrregularCycle,
|
||||
isPadTrackingEnabled: _isPadTrackingEnabled,
|
||||
);
|
||||
ref.read(userProfileProvider.notifier).updateProfile(updatedProfile);
|
||||
Navigator.of(context).pop();
|
||||
@@ -130,6 +133,19 @@ class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
|
||||
});
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('Enable Pad Tracking'),
|
||||
subtitle:
|
||||
const Text('Track supply usage and receive change reminders'),
|
||||
value: _isPadTrackingEnabled,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_isPadTrackingEnabled = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
ElevatedButton(
|
||||
onPressed: _saveSettings,
|
||||
|
||||
@@ -43,22 +43,49 @@ class ExportDataScreen extends ConsumerWidget {
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.calendar_month),
|
||||
title: const Text('Export to Calendar File (.ics)'),
|
||||
subtitle: const Text('Generate a calendar file for your cycle dates.'),
|
||||
leading: const Icon(Icons.sync),
|
||||
title: const Text('Sync with Calendar'),
|
||||
subtitle: const Text('Export to Apple, Google, or Outlook Calendar.'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
// Show options dialog
|
||||
final includePredictions = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Calendar Sync Options'),
|
||||
content: const Text('Would you like to include predicted future periods for the next 12 months?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('No, only history'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('Yes, include predictions'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (includePredictions == null) return; // User cancelled dialog (though I didn't add cancel button, tapping outside returns null)
|
||||
|
||||
try {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Generating ICS file...')),
|
||||
const SnackBar(content: Text('Generating calendar file...')),
|
||||
);
|
||||
await IcsService.generateCycleCalendar(cycleEntries);
|
||||
|
||||
await IcsService.generateCycleCalendar(
|
||||
cycleEntries,
|
||||
user: userProfile,
|
||||
includePredictions: includePredictions
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('ICS file generated successfully!')),
|
||||
const SnackBar(content: Text('Calendar file generated! Open it to add to your calendar.')),
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to generate ICS file: $e')),
|
||||
SnackBar(content: Text('Failed to generate calendar file: $e')),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -56,6 +56,60 @@ class NotificationSettingsScreen extends ConsumerWidget {
|
||||
.updateProfile(userProfile.copyWith(notifyLowSupply: value));
|
||||
},
|
||||
),
|
||||
if (userProfile.isPadTrackingEnabled) ...[
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
|
||||
child: Text(
|
||||
'Pad Change Reminders',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('2 Hours Before'),
|
||||
value: userProfile.notifyPad2Hours,
|
||||
onChanged: (value) async {
|
||||
if (value != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
userProfile.copyWith(notifyPad2Hours: value));
|
||||
}
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('1 Hour Before'),
|
||||
value: userProfile.notifyPad1Hour,
|
||||
onChanged: (value) async {
|
||||
if (value != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
userProfile.copyWith(notifyPad1Hour: value));
|
||||
}
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('30 Minutes Before'),
|
||||
value: userProfile.notifyPad30Mins,
|
||||
onChanged: (value) async {
|
||||
if (value != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
userProfile.copyWith(notifyPad30Mins: value));
|
||||
}
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Change Now (Time\'s Up)'),
|
||||
subtitle: const Text('Get notified when it\'s recommended to change.'),
|
||||
value: userProfile.notifyPadNow,
|
||||
onChanged: (value) async {
|
||||
if (value != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
userProfile.copyWith(notifyPadNow: value));
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -76,8 +76,6 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Period data synced successfully!')),
|
||||
);
|
||||
// Optionally store a flag in userProfile if sync is active
|
||||
// userProfile.copyWith(syncPeriodToHealth: true)
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Failed to sync period data.')),
|
||||
@@ -86,8 +84,6 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Logic to disable sync (e.g., revoke permissions if Health package supports it,
|
||||
// or just stop writing data in future)
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Period data sync disabled.')),
|
||||
@@ -97,10 +93,71 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
setState(() {}); // Rebuild to update UI
|
||||
}
|
||||
|
||||
Future<void> _setPin() async {
|
||||
final pin = await _showPinDialog(context, title: 'Set New PIN');
|
||||
if (pin != null && pin.length >= 4) {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(user.copyWith(privacyPin: pin));
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('PIN Set Successfully')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _removePin() async {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user == null) return;
|
||||
|
||||
// Require current PIN
|
||||
final currentPin = await _showPinDialog(context, title: 'Enter Current PIN');
|
||||
if (currentPin == user.privacyPin) {
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(
|
||||
// To clear fields, copyWith might need to handle nulls explicitly if written that way,
|
||||
// but here we might pass empty string or handle logic.
|
||||
// Actually, copyWith signature usually ignores nulls.
|
||||
// I'll assume updating with empty string or handle it in provider,
|
||||
// but for now let's just use empty string to signify removal if logic supports it.
|
||||
// Wait, copyWith `privacyPin: privacyPin ?? this.privacyPin`.
|
||||
// If I pass null, it keeps existing. I can't clear it via standard copyWith unless I change copyWith logic or pass emptiness.
|
||||
// I'll update the userProfile object directly and save? No, Hive object.
|
||||
// For now, let's treat "empty string" as no PIN if I can pass it.
|
||||
user.copyWith(privacyPin: '', isBioProtected: false, isHistoryProtected: false)
|
||||
);
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('PIN Removed')));
|
||||
} else {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Incorrect PIN')));
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _showPinDialog(BuildContext context, {required String title}) {
|
||||
final controller = TextEditingController();
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
obscureText: true,
|
||||
maxLength: 4,
|
||||
decoration: const InputDecoration(hintText: 'Enter 4-digit PIN'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context, controller.text),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This value would ideally come from userProfile.syncPeriodToHealth
|
||||
bool syncPeriodToHealth = _hasPermissions;
|
||||
final user = ref.watch(userProfileProvider);
|
||||
final hasPin = user?.privacyPin != null && user!.privacyPin!.isNotEmpty;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -109,17 +166,100 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
// Security Section
|
||||
Text('App Security', style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
const SizedBox(height: 8),
|
||||
ListTile(
|
||||
title: const Text('Health App Integration'),
|
||||
title: const Text('Privacy PIN'),
|
||||
subtitle: Text(hasPin ? 'PIN is set' : 'Protect sensitive data with a PIN'),
|
||||
trailing: hasPin ? const Icon(Icons.lock, color: Colors.green) : const Icon(Icons.lock_open),
|
||||
onTap: () {
|
||||
if (hasPin) {
|
||||
showModalBottomSheet(context: context, builder: (context) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.edit),
|
||||
title: const Text('Change PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_setPin();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete, color: Colors.red),
|
||||
title: const Text('Remove PIN'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_removePin();
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
} else {
|
||||
_setPin();
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
if (hasPin) ...[
|
||||
SwitchListTile(
|
||||
title: const Text('Use Biometrics'),
|
||||
subtitle: const Text('Unlock with FaceID / Fingerprint'),
|
||||
value: user?.isBioProtected ?? false,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isBioProtected: val));
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
const Text('Protected Features', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
|
||||
SwitchListTile(
|
||||
title: const Text('Daily Logs'),
|
||||
value: user?.isLogProtected ?? false,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isLogProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Calendar'),
|
||||
value: user?.isCalendarProtected ?? false,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isCalendarProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Supplies / Pad Tracker'),
|
||||
value: user?.isSuppliesProtected ?? false,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isSuppliesProtected: val));
|
||||
},
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Cycle History'),
|
||||
value: user?.isHistoryProtected ?? false,
|
||||
onChanged: (val) {
|
||||
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isHistoryProtected: val));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
const Divider(height: 32),
|
||||
|
||||
// Health Section
|
||||
Text('Health App Integration', style: Theme.of(context).textTheme.titleMedium?.copyWith(color: Theme.of(context).colorScheme.primary)),
|
||||
const SizedBox(height: 8),
|
||||
ListTile(
|
||||
title: const Text('Health Source'),
|
||||
subtitle: _hasPermissions
|
||||
? const Text('Connected to Health App. Period data can be synced.')
|
||||
? const Text('Connected to Health App.')
|
||||
: const Text('Not connected. Tap to grant access.'),
|
||||
trailing: _hasPermissions ? const Icon(Icons.check_circle, color: Colors.green) : const Icon(Icons.warning, color: Colors.orange),
|
||||
onTap: _requestPermissions,
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Sync Period Days'),
|
||||
subtitle: const Text('Automatically sync your period start and end dates to your health app.'),
|
||||
subtitle: const Text('Automatically sync period dates.'),
|
||||
value: syncPeriodToHealth,
|
||||
onChanged: _hasPermissions ? (value) async {
|
||||
if (value) {
|
||||
@@ -132,7 +272,6 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
|
||||
});
|
||||
} : null,
|
||||
),
|
||||
// TODO: Add more privacy settings if needed
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../models/user_profile.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../models/teaching_plan.dart';
|
||||
|
||||
class RelationshipSettingsScreen extends ConsumerWidget {
|
||||
const RelationshipSettingsScreen({super.key});
|
||||
@@ -23,6 +24,34 @@ class RelationshipSettingsScreen extends ConsumerWidget {
|
||||
'Select your current relationship status to customize your experience.',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Sample Data Button
|
||||
Center(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null) {
|
||||
final samplePlan = TeachingPlan.create(
|
||||
topic: 'Walking in Love',
|
||||
scriptureReference: 'Ephesians 5:1-2',
|
||||
notes: 'As Christ loved us and gave himself up for us, a fragrant offering and sacrifice to God. Let our marriage reflect this sacrificial love.',
|
||||
date: DateTime.now(),
|
||||
);
|
||||
|
||||
final List<TeachingPlan> updatedPlans = [...(user.teachingPlans ?? []), samplePlan];
|
||||
ref.read(userProfileProvider.notifier).updateProfile(
|
||||
user.copyWith(teachingPlans: updatedPlans)
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Sample Teaching Plan Loaded! Check Devotional page.')),
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.science_outlined),
|
||||
label: const Text('Load Sample Teaching Plan (Demo)'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_buildOption(
|
||||
context,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/user_profile.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
|
||||
@@ -31,10 +33,7 @@ class SharingSettingsScreen extends ConsumerWidget {
|
||||
title: const Text('Link with Husband'),
|
||||
subtitle: Text(userProfile.partnerName != null ? 'Linked to ${userProfile.partnerName}' : 'Not linked'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
// TODO: Navigate to Link Screen or Show Dialog
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Link feature coming soon!')));
|
||||
},
|
||||
onTap: () => _showShareDialog(context, ref),
|
||||
),
|
||||
const Divider(),
|
||||
SwitchListTile(
|
||||
@@ -95,4 +94,66 @@ class SharingSettingsScreen extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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: Row(
|
||||
children: [
|
||||
Icon(Icons.share_outlined, color: AppColors.navyBlue),
|
||||
const SizedBox(width: 8),
|
||||
const 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.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.navyBlue.withOpacity(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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/user_profile.dart';
|
||||
import '../../providers/user_provider.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../../widgets/pad_settings_dialog.dart'; // We can reuse the logic, but maybe embed it directly or just link it.
|
||||
@@ -19,16 +20,15 @@ class SuppliesSettingsScreen extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen> {
|
||||
// Logic from PadSettingsDialog
|
||||
bool _isTrackingEnabled = false;
|
||||
int _typicalFlow = 2;
|
||||
int _padAbsorbency = 3;
|
||||
int _padInventoryCount = 0;
|
||||
int _lowInventoryThreshold = 5;
|
||||
bool _isAutoInventoryEnabled = true;
|
||||
bool _showPadTimerMinutes = true;
|
||||
bool _showPadTimerSeconds = false;
|
||||
final TextEditingController _brandController = TextEditingController();
|
||||
|
||||
// Inventory
|
||||
List<SupplyItem> _supplies = [];
|
||||
int _lowInventoryThreshold = 5;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -37,43 +37,44 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
|
||||
if (user != null) {
|
||||
_isTrackingEnabled = user.isPadTrackingEnabled;
|
||||
_typicalFlow = user.typicalFlowIntensity ?? 2;
|
||||
_padAbsorbency = user.padAbsorbency ?? 3;
|
||||
_padInventoryCount = user.padInventoryCount;
|
||||
_lowInventoryThreshold = user.lowInventoryThreshold;
|
||||
_isAutoInventoryEnabled = user.isAutoInventoryEnabled;
|
||||
_brandController.text = user.padBrand ?? '';
|
||||
_lowInventoryThreshold = user.lowInventoryThreshold;
|
||||
_showPadTimerMinutes = user.showPadTimerMinutes;
|
||||
_showPadTimerSeconds = user.showPadTimerSeconds;
|
||||
|
||||
// Load supplies
|
||||
if (user.padSupplies != null) {
|
||||
_supplies = List.from(user.padSupplies!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_brandController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _saveSettings() async {
|
||||
final user = ref.read(userProfileProvider);
|
||||
if (user != null) {
|
||||
// Calculate total inventory count for the legacy field
|
||||
int totalCount = _supplies.fold(0, (sum, item) => sum + item.count);
|
||||
|
||||
final updatedProfile = user.copyWith(
|
||||
isPadTrackingEnabled: _isTrackingEnabled,
|
||||
typicalFlowIntensity: _typicalFlow,
|
||||
isAutoInventoryEnabled: _isAutoInventoryEnabled,
|
||||
padBrand: _brandController.text.trim().isEmpty ? null : _brandController.text.trim(),
|
||||
showPadTimerMinutes: _showPadTimerMinutes,
|
||||
showPadTimerSeconds: _showPadTimerSeconds,
|
||||
padSupplies: _supplies,
|
||||
padInventoryCount: totalCount,
|
||||
lowInventoryThreshold: _lowInventoryThreshold,
|
||||
);
|
||||
|
||||
await ref.read(userProfileProvider.notifier).updateProfile(updatedProfile);
|
||||
|
||||
// Check for Low Supply Alert
|
||||
if (updatedProfile.notifyLowSupply &&
|
||||
updatedProfile.padInventoryCount <= updatedProfile.lowInventoryThreshold) {
|
||||
totalCount <= updatedProfile.lowInventoryThreshold) {
|
||||
NotificationService().showLocalNotification(
|
||||
id: 2001,
|
||||
title: 'Low Pad Supply',
|
||||
body: 'Your inventory is low (${updatedProfile.padInventoryCount} left). Time to restock!',
|
||||
body: 'Your inventory is low ($totalCount left). Time to restock!',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,6 +86,24 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
|
||||
}
|
||||
}
|
||||
|
||||
void _addOrEditSupply({SupplyItem? item, int? index}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => _SupplyDialog(
|
||||
initialItem: item,
|
||||
onSave: (newItem) {
|
||||
setState(() {
|
||||
if (index != null) {
|
||||
_supplies[index] = newItem;
|
||||
} else {
|
||||
_supplies.add(newItem);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -126,6 +145,83 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
|
||||
if (_isTrackingEnabled) ...[
|
||||
const Divider(height: 32),
|
||||
|
||||
// Inventory Section
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'My Inventory',
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.warmGray,
|
||||
),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () => _addOrEditSupply(),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add Item'),
|
||||
style: TextButton.styleFrom(foregroundColor: AppColors.menstrualPhase),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (_supplies.isEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'No supplies added yet.\nAdd items to track specific inventory.',
|
||||
textAlign: TextAlign.center,
|
||||
style: GoogleFonts.outfit(color: AppColors.warmGray),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: _supplies.length,
|
||||
separatorBuilder: (c, i) => const SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final item = _supplies[index];
|
||||
return ListTile(
|
||||
tileColor: Theme.of(context).cardTheme.color,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(color: Colors.black.withOpacity(0.05)),
|
||||
),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: AppColors.menstrualPhase.withOpacity(0.1),
|
||||
child: Text(
|
||||
item.count.toString(),
|
||||
style: GoogleFonts.outfit(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.menstrualPhase,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(item.brand, style: GoogleFonts.outfit(fontWeight: FontWeight.w600)),
|
||||
subtitle: Text(item.type.label, style: GoogleFonts.outfit(fontSize: 12)),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete_outline, color: Colors.red),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_supplies.removeAt(index);
|
||||
});
|
||||
},
|
||||
),
|
||||
onTap: () => _addOrEditSupply(item: item, index: index),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(height: 32),
|
||||
|
||||
// Typical Flow
|
||||
Text(
|
||||
'Typical Flow Intensity',
|
||||
@@ -230,3 +326,86 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SupplyDialog extends StatefulWidget {
|
||||
final SupplyItem? initialItem;
|
||||
final Function(SupplyItem) onSave;
|
||||
|
||||
const _SupplyDialog({this.initialItem, required this.onSave});
|
||||
|
||||
@override
|
||||
State<_SupplyDialog> createState() => _SupplyDialogState();
|
||||
}
|
||||
|
||||
class _SupplyDialogState extends State<_SupplyDialog> {
|
||||
late TextEditingController _brandController;
|
||||
late PadType _type;
|
||||
late int _count;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_brandController = TextEditingController(text: widget.initialItem?.brand ?? '');
|
||||
_type = widget.initialItem?.type ?? PadType.regular;
|
||||
_count = widget.initialItem?.count ?? 0;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_brandController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(widget.initialItem == null ? 'Add Supply' : 'Edit Supply'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _brandController,
|
||||
decoration: const InputDecoration(labelText: 'Brand / Name'),
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<PadType>(
|
||||
value: _type,
|
||||
items: PadType.values.map((t) => DropdownMenuItem(
|
||||
value: t,
|
||||
child: Text(t.label),
|
||||
)).toList(),
|
||||
onChanged: (val) => setState(() => _type = val!),
|
||||
decoration: const InputDecoration(labelText: 'Type'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(labelText: 'Quantity'),
|
||||
controller: TextEditingController(text: _count.toString()), // Hacky for demo, binding needed properly
|
||||
onChanged: (val) => _count = int.tryParse(val) ?? 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_brandController.text.isEmpty) return;
|
||||
final newItem = SupplyItem(
|
||||
brand: _brandController.text.trim(),
|
||||
type: _type,
|
||||
absorbency: 3, // Default for now
|
||||
count: _count,
|
||||
);
|
||||
widget.onSave(newItem);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user