Resolve all lints and deprecation warnings

This commit is contained in:
2026-01-09 10:04:51 -06:00
parent 512577b092
commit a799e9cf59
56 changed files with 2819 additions and 3159 deletions

View File

@@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../models/user_profile.dart';
import '../../providers/user_provider.dart';
import '../../theme/app_theme.dart';
import '../../widgets/pad_settings_dialog.dart';
class AppearanceScreen extends ConsumerWidget {
const AppearanceScreen({super.key});
@@ -43,41 +42,42 @@ class AppearanceScreen extends ConsumerWidget {
),
const SizedBox(height: 16),
SegmentedButton<AppThemeMode>(
segments: const [
ButtonSegment(
value: AppThemeMode.light,
label: Text('Light'),
icon: Icon(Icons.light_mode),
),
ButtonSegment(
value: AppThemeMode.dark,
label: Text('Dark'),
icon: Icon(Icons.dark_mode),
),
ButtonSegment(
value: AppThemeMode.system,
label: Text('System'),
icon: Icon(Icons.brightness_auto),
),
],
selected: {currentMode},
onSelectionChanged: (Set<AppThemeMode> newSelection) {
if (newSelection.isNotEmpty) {
ref
.read(userProfileProvider.notifier)
.updateThemeMode(newSelection.first);
}
},
style: SegmentedButton.styleFrom(
fixedSize: const Size.fromHeight(48),
)
),
segments: const [
ButtonSegment(
value: AppThemeMode.light,
label: Text('Light'),
icon: Icon(Icons.light_mode),
),
ButtonSegment(
value: AppThemeMode.dark,
label: Text('Dark'),
icon: Icon(Icons.dark_mode),
),
ButtonSegment(
value: AppThemeMode.system,
label: Text('System'),
icon: Icon(Icons.brightness_auto),
),
],
selected: {
currentMode
},
onSelectionChanged: (Set<AppThemeMode> newSelection) {
if (newSelection.isNotEmpty) {
ref
.read(userProfileProvider.notifier)
.updateThemeMode(newSelection.first);
}
},
style: SegmentedButton.styleFrom(
fixedSize: const Size.fromHeight(48),
)),
],
);
}
Widget _buildAccentColorSelector(BuildContext context, WidgetRef ref,
String currentAccent) {
Widget _buildAccentColorSelector(
BuildContext context, WidgetRef ref, String currentAccent) {
final accents = [
{'color': AppColors.sageGreen, 'value': '0xFFA8C5A8'},
{'color': AppColors.rose, 'value': '0xFFE8A0B0'},
@@ -125,7 +125,7 @@ class AppearanceScreen extends ConsumerWidget {
boxShadow: [
if (isSelected)
BoxShadow(
color: color.withOpacity(0.4),
color: color.withValues(alpha: 0.4),
blurRadius: 8,
offset: const Offset(0, 4),
)
@@ -141,4 +141,4 @@ class AppearanceScreen extends ConsumerWidget {
],
);
}
}
}

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import '../../models/user_profile.dart';
import '../../providers/user_provider.dart';
class CycleSettingsScreen extends ConsumerStatefulWidget {
@@ -45,8 +44,10 @@ class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
final userProfile = ref.read(userProfileProvider);
if (userProfile != null) {
final updatedProfile = userProfile.copyWith(
averageCycleLength: int.tryParse(_cycleLengthController.text) ?? userProfile.averageCycleLength,
averagePeriodLength: int.tryParse(_periodLengthController.text) ?? userProfile.averagePeriodLength,
averageCycleLength: int.tryParse(_cycleLengthController.text) ??
userProfile.averageCycleLength,
averagePeriodLength: int.tryParse(_periodLengthController.text) ??
userProfile.averagePeriodLength,
lastPeriodStartDate: _lastPeriodStartDate,
isIrregularCycle: _isIrregularCycle,
isPadTrackingEnabled: _isPadTrackingEnabled,

View File

@@ -24,28 +24,40 @@ class ExportDataScreen extends ConsumerWidget {
ListTile(
leading: const Icon(Icons.picture_as_pdf),
title: const Text('Export as PDF'),
subtitle: const Text('Generate a printable PDF report of your cycle data.'),
subtitle: const Text(
'Generate a printable PDF report of your cycle data.'),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
try {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Generating PDF report...')),
);
await PdfService.generateCycleReport(userProfile, cycleEntries);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('PDF report generated successfully!')),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Generating PDF report...')),
);
}
await PdfService.generateCycleReport(
userProfile, cycleEntries);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('PDF report generated successfully!')),
);
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to generate PDF: $e')),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to generate PDF: $e')),
);
}
}
},
),
ListTile(
leading: const Icon(Icons.sync),
title: const Text('Sync with Calendar'),
subtitle: const Text('Export to Apple, Google, or Outlook Calendar.'),
subtitle: const Text(
'Export to Apple, Google, or Outlook Calendar.'),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
// Show options dialog
@@ -53,7 +65,8 @@ class ExportDataScreen extends ConsumerWidget {
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?'),
content: const Text(
'Would you like to include predicted future periods for the next 12 months?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
@@ -67,26 +80,37 @@ class ExportDataScreen extends ConsumerWidget {
),
);
if (includePredictions == null) return; // User cancelled dialog (though I didn't add cancel button, tapping outside returns null)
if (includePredictions == null) {
return; // User cancelled dialog
}
try {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Generating calendar file...')),
);
await IcsService.generateCycleCalendar(
cycleEntries,
user: userProfile,
includePredictions: includePredictions
);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Calendar file generated! Open it to add to your calendar.')),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Generating calendar file...')),
);
}
await IcsService.generateCycleCalendar(cycleEntries,
user: userProfile,
includePredictions: includePredictions);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
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 calendar file: $e')),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text('Failed to generate calendar file: $e')),
);
}
}
},
),

View File

@@ -18,47 +18,60 @@ class GoalSettingsScreen extends ConsumerWidget {
appBar: AppBar(
title: const Text('Cycle Goal'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
children: [
const Text(
'What is your current goal?',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
const Text(
'Select your primary goal to get personalized insights and predictions.',
style: TextStyle(fontSize: 14, color: Colors.grey),
),
const SizedBox(height: 24),
_buildGoalOption(
context,
ref,
title: 'Track Cycle Only',
subtitle: 'Monitor period and health without fertility focus',
value: FertilityGoal.justTracking,
groupValue: userProfile.fertilityGoal,
icon: Icons.calendar_today,
),
_buildGoalOption(
context,
ref,
title: 'Achieve Pregnancy',
subtitle: 'Identify fertile window and ovulation',
value: FertilityGoal.tryingToConceive,
groupValue: userProfile.fertilityGoal,
icon: Icons.child_friendly,
),
_buildGoalOption(
context,
ref,
title: 'Avoid Pregnancy',
subtitle: 'Track fertility for natural family planning',
value: FertilityGoal.tryingToAvoid,
groupValue: userProfile.fertilityGoal,
icon: Icons.security,
),
],
body: RadioGroup<FertilityGoal>(
groupValue: userProfile.fertilityGoal,
onChanged: (FertilityGoal? newValue) {
if (newValue != null) {
final currentProfile = ref.read(userProfileProvider);
if (currentProfile != null) {
ref.read(userProfileProvider.notifier).updateProfile(
currentProfile.copyWith(fertilityGoal: newValue),
);
}
}
},
child: ListView(
padding: const EdgeInsets.all(16.0),
children: [
const Text(
'What is your current goal?',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
const Text(
'Select your primary goal to get personalized insights and predictions.',
style: TextStyle(fontSize: 14, color: Colors.grey),
),
const SizedBox(height: 24),
_buildGoalOption(
context,
ref,
title: 'Track Cycle Only',
subtitle: 'Monitor period and health without fertility focus',
value: FertilityGoal.justTracking,
groupValue: userProfile.fertilityGoal,
icon: Icons.calendar_today,
),
_buildGoalOption(
context,
ref,
title: 'Achieve Pregnancy',
subtitle: 'Identify fertile window and ovulation',
value: FertilityGoal.tryingToConceive,
groupValue: userProfile.fertilityGoal,
icon: Icons.child_friendly,
),
_buildGoalOption(
context,
ref,
title: 'Avoid Pregnancy',
subtitle: 'Track fertility for natural family planning',
value: FertilityGoal.tryingToAvoid,
groupValue: userProfile.fertilityGoal,
icon: Icons.security,
),
],
),
),
);
}
@@ -85,20 +98,10 @@ class GoalSettingsScreen extends ConsumerWidget {
),
child: RadioListTile<FertilityGoal>(
value: value,
groupValue: groupValue,
onChanged: (FertilityGoal? newValue) {
if (newValue != null) {
final currentProfile = ref.read(userProfileProvider);
if (currentProfile != null) {
ref.read(userProfileProvider.notifier).updateProfile(
currentProfile.copyWith(fertilityGoal: newValue),
);
}
}
},
title: Text(title, style: const TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text(subtitle),
secondary: Icon(icon, color: isSelected ? Theme.of(context).colorScheme.primary : null),
secondary: Icon(icon,
color: isSelected ? Theme.of(context).colorScheme.primary : null),
activeColor: Theme.of(context).colorScheme.primary,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../models/user_profile.dart'; // Import UserProfile
import '../../providers/user_provider.dart';
class NotificationSettingsScreen extends ConsumerWidget {
@@ -26,29 +25,30 @@ class NotificationSettingsScreen extends ConsumerWidget {
children: [
SwitchListTile(
title: const Text('Period Estimate'),
subtitle: const Text('Get notified when your period is predicted to start soon.'),
subtitle: const Text(
'Get notified when your period is predicted to start soon.'),
value: userProfile.notifyPeriodEstimate,
onChanged: (value) async {
await ref
.read(userProfileProvider.notifier)
.updateProfile(userProfile.copyWith(notifyPeriodEstimate: value));
await ref.read(userProfileProvider.notifier).updateProfile(
userProfile.copyWith(notifyPeriodEstimate: value));
},
),
const Divider(),
SwitchListTile(
title: const Text('Period Start'),
subtitle: const Text('Get notified when a period starts (or husband needs to know).'),
subtitle: const Text(
'Get notified when a period starts (or husband needs to know).'),
value: userProfile.notifyPeriodStart,
onChanged: (value) async {
await ref
.read(userProfileProvider.notifier)
.updateProfile(userProfile.copyWith(notifyPeriodStart: value));
await ref.read(userProfileProvider.notifier).updateProfile(
userProfile.copyWith(notifyPeriodStart: value));
},
),
const Divider(),
SwitchListTile(
title: const Text('Low Supply Alert'),
subtitle: const Text('Get notified when pad inventory is running low.'),
subtitle:
const Text('Get notified when pad inventory is running low.'),
value: userProfile.notifyLowSupply,
onChanged: (value) async {
await ref
@@ -58,14 +58,15 @@ class NotificationSettingsScreen extends ConsumerWidget {
),
if (userProfile.isPadTrackingEnabled) ...[
const Divider(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
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,
),
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
CheckboxListTile(
@@ -100,12 +101,14 @@ class NotificationSettingsScreen extends ConsumerWidget {
),
CheckboxListTile(
title: const Text('Change Now (Time\'s Up)'),
subtitle: const Text('Get notified when it\'s recommended to change.'),
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));
await ref
.read(userProfileProvider.notifier)
.updateProfile(userProfile.copyWith(notifyPadNow: value));
}
},
),

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:health/health.dart';
import '../../providers/user_provider.dart';
import '../../services/health_service.dart';
@@ -23,24 +23,30 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
}
Future<void> _checkPermissions() async {
final hasPermissions = await _healthService.hasPermissions(_healthService.menstruationDataTypes);
final hasPermissions = await _healthService
.hasPermissions(_healthService.menstruationDataTypes);
setState(() {
_hasPermissions = hasPermissions;
});
}
Future<void> _requestPermissions() async {
final authorized = await _healthService.requestAuthorization(_healthService.menstruationDataTypes);
final authorized = await _healthService
.requestAuthorization(_healthService.menstruationDataTypes);
if (authorized) {
_hasPermissions = true;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Health app access granted!')),
);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Health app access granted!')),
);
}
} else {
_hasPermissions = false;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Health app access denied.')),
);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Health app access denied.')),
);
}
}
setState(() {}); // Rebuild to update UI
}
@@ -48,14 +54,17 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
Future<void> _syncPeriodDays(bool sync) async {
if (sync) {
if (!_hasPermissions) {
// Request permissions if not already granted
final authorized = await _healthService.requestAuthorization(_healthService.menstruationDataTypes);
if (!authorized) {
if (mounted) {
final authorized = await _healthService
.requestAuthorization(_healthService.menstruationDataTypes);
if (mounted) {
if (!authorized) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cannot sync without health app permissions.')),
const SnackBar(
content: Text('Cannot sync without health app permissions.')),
);
return;
}
} else {
return;
}
_hasPermissions = true;
@@ -70,7 +79,8 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
final cycleEntries = ref.read(cycleEntriesProvider);
if (userProfile != null) {
final success = await _healthService.writeMenstruationData(cycleEntries);
final success =
await _healthService.writeMenstruationData(cycleEntries);
if (mounted) {
if (success) {
ScaffoldMessenger.of(context).showSnackBar(
@@ -90,7 +100,7 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
);
}
}
setState(() {}); // Rebuild to update UI
setState(() {});
}
Future<void> _setPin() async {
@@ -98,38 +108,40 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
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')));
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');
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')));
await ref.read(userProfileProvider.notifier).updateProfile(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')));
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Incorrect PIN')));
}
}
}
Future<String?> _showPinDialog(BuildContext context, {required String title}) {
Future<String?> _showPinDialog(BuildContext context,
{required String title}) {
final controller = TextEditingController();
return showDialog<String>(
context: context,
@@ -143,7 +155,9 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
decoration: const InputDecoration(hintText: 'Enter 4-digit PIN'),
),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel')),
ElevatedButton(
onPressed: () => Navigator.pop(context, controller.text),
child: const Text('OK'),
@@ -155,9 +169,13 @@ class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
@override
Widget build(BuildContext context) {
bool syncPeriodToHealth = _hasPermissions;
final user = ref.watch(userProfileProvider);
final hasPin = user?.privacyPin != null && user!.privacyPin!.isNotEmpty;
if (user == null) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
final hasPin = user.privacyPin != null && user.privacyPin!.isNotEmpty;
bool syncPeriodToHealth = _hasPermissions;
return Scaffold(
appBar: AppBar(
@@ -166,111 +184,135 @@ 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)),
Text('App Security',
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Theme.of(context).colorScheme.primary)),
const SizedBox(height: 8),
ListTile(
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),
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();
},
),
],
));
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,
value: user.isBioProtected,
onChanged: (val) {
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isBioProtected: val));
ref
.read(userProfileProvider.notifier)
.updateProfile(user.copyWith(isBioProtected: val));
},
),
const Divider(),
const Text('Protected Features', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
const Text('Protected Features',
style:
TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
SwitchListTile(
title: const Text('Daily Logs'),
value: user?.isLogProtected ?? false,
value: user.isLogProtected,
onChanged: (val) {
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isLogProtected: val));
ref
.read(userProfileProvider.notifier)
.updateProfile(user.copyWith(isLogProtected: val));
},
),
SwitchListTile(
SwitchListTile(
title: const Text('Calendar'),
value: user?.isCalendarProtected ?? false,
value: user.isCalendarProtected,
onChanged: (val) {
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isCalendarProtected: val));
ref
.read(userProfileProvider.notifier)
.updateProfile(user.copyWith(isCalendarProtected: val));
},
),
SwitchListTile(
SwitchListTile(
title: const Text('Supplies / Pad Tracker'),
value: user?.isSuppliesProtected ?? false,
value: user.isSuppliesProtected,
onChanged: (val) {
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isSuppliesProtected: val));
ref
.read(userProfileProvider.notifier)
.updateProfile(user.copyWith(isSuppliesProtected: val));
},
),
SwitchListTile(
title: const Text('Cycle History'),
value: user?.isHistoryProtected ?? false,
value: user.isHistoryProtected,
onChanged: (val) {
ref.read(userProfileProvider.notifier).updateProfile(user!.copyWith(isHistoryProtected: 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)),
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.')
: 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),
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 period dates.'),
value: syncPeriodToHealth,
onChanged: _hasPermissions ? (value) async {
if (value) {
await _syncPeriodDays(true);
} else {
await _syncPeriodDays(false);
}
setState(() {
syncPeriodToHealth = value; // Update local state for toggle
});
} : null,
onChanged: _hasPermissions
? (value) async {
if (value) {
await _syncPeriodDays(true);
} else {
await _syncPeriodDays(false);
}
setState(() {
syncPeriodToHealth = value;
});
}
: null,
),
],
),

View File

@@ -17,70 +17,85 @@ class RelationshipSettingsScreen extends ConsumerWidget {
),
body: userProfile == null
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16.0),
children: [
const Text(
'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)'),
: RadioGroup<RelationshipStatus>(
groupValue: userProfile.relationshipStatus,
onChanged: (RelationshipStatus? newValue) {
if (newValue != null) {
ref
.read(userProfileProvider.notifier)
.updateRelationshipStatus(newValue);
}
},
child: ListView(
padding: const EdgeInsets.all(16.0),
children: [
const Text(
'Select your current relationship status to customize your experience.',
style: TextStyle(fontSize: 16),
),
),
const SizedBox(height: 24),
_buildOption(
context,
ref,
title: 'Single',
subtitle: 'Tracking for potential future',
value: RelationshipStatus.single,
groupValue: userProfile.relationshipStatus,
icon: Icons.person_outline,
),
_buildOption(
context,
ref,
title: 'Engaged',
subtitle: 'Preparing for marriage',
value: RelationshipStatus.engaged,
groupValue: userProfile.relationshipStatus,
icon: Icons.favorite_border,
),
_buildOption(
context,
ref,
title: 'Married',
subtitle: 'Tracking together with husband',
value: RelationshipStatus.married,
groupValue: userProfile.relationshipStatus,
icon: Icons.favorite,
),
],
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,
ref,
title: 'Single',
subtitle: 'Tracking for potential future',
value: RelationshipStatus.single,
groupValue: userProfile.relationshipStatus,
icon: Icons.person_outline,
),
_buildOption(
context,
ref,
title: 'Engaged',
subtitle: 'Preparing for marriage',
value: RelationshipStatus.engaged,
groupValue: userProfile.relationshipStatus,
icon: Icons.favorite_border,
),
_buildOption(
context,
ref,
title: 'Married',
subtitle: 'Tracking together with husband',
value: RelationshipStatus.married,
groupValue: userProfile.relationshipStatus,
icon: Icons.favorite,
),
],
),
),
);
}
@@ -98,7 +113,7 @@ class RelationshipSettingsScreen extends ConsumerWidget {
return Card(
elevation: isSelected ? 2 : 0,
shape: RoundedRectangleBorder(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: isSelected
? BorderSide(color: Theme.of(context).colorScheme.primary, width: 2)
@@ -106,17 +121,10 @@ class RelationshipSettingsScreen extends ConsumerWidget {
),
child: RadioListTile<RelationshipStatus>(
value: value,
groupValue: groupValue,
onChanged: (RelationshipStatus? newValue) {
if (newValue != null) {
ref
.read(userProfileProvider.notifier)
.updateRelationshipStatus(newValue);
}
},
title: Text(title, style: const TextStyle(fontWeight: FontWeight.w600)),
subtitle: Text(subtitle),
secondary: Icon(icon, color: isSelected ? Theme.of(context).colorScheme.primary : null),
secondary: Icon(icon,
color: isSelected ? Theme.of(context).colorScheme.primary : null),
activeColor: Theme.of(context).colorScheme.primary,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),

View File

@@ -2,7 +2,6 @@ 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';
class SharingSettingsScreen extends ConsumerWidget {
@@ -31,7 +30,9 @@ class SharingSettingsScreen extends ConsumerWidget {
ListTile(
leading: const Icon(Icons.link),
title: const Text('Link with Husband'),
subtitle: Text(userProfile.partnerName != null ? 'Linked to ${userProfile.partnerName}' : 'Not linked'),
subtitle: Text(userProfile.partnerName != null
? 'Linked to ${userProfile.partnerName}'
: 'Not linked'),
trailing: const Icon(Icons.chevron_right),
onTap: () => _showShareDialog(context, ref),
),
@@ -67,9 +68,8 @@ class SharingSettingsScreen extends ConsumerWidget {
title: const Text('Share Energy Levels'),
value: userProfile.shareEnergyLevels,
onChanged: (value) {
ref
.read(userProfileProvider.notifier)
.updateProfile(userProfile.copyWith(shareEnergyLevels: value));
ref.read(userProfileProvider.notifier).updateProfile(
userProfile.copyWith(shareEnergyLevels: value));
},
),
SwitchListTile(
@@ -98,16 +98,17 @@ 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';
final pairingCode =
userProfile?.id.substring(0, 6).toUpperCase() ?? 'ABC123';
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Row(
title: const Row(
children: [
Icon(Icons.share_outlined, color: AppColors.navyBlue),
const SizedBox(width: 8),
const Text('Share with Husband'),
SizedBox(width: 8),
Text('Share with Husband'),
],
),
content: Column(
@@ -115,15 +116,17 @@ class SharingSettingsScreen extends ConsumerWidget {
children: [
Text(
'Share this code with your husband so he can connect to your cycle data:',
style: GoogleFonts.outfit(fontSize: 14, color: AppColors.warmGray),
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),
color: AppColors.navyBlue.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.navyBlue.withOpacity(0.3)),
border: Border.all(
color: AppColors.navyBlue.withValues(alpha: 0.3)),
),
child: SelectableText(
pairingCode,
@@ -138,7 +141,8 @@ class SharingSettingsScreen extends ConsumerWidget {
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),
style:
GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray),
textAlign: TextAlign.center,
),
],

View File

@@ -5,10 +5,9 @@ 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.
// Actually, let's rebuild the UI here properly as a screen instead of a dialog,
// or for now, since we already have the dialog logic working well, let's just
// have this screen trigger the dialog or embed the same widgets.
// or for now, since we already have the dialog logic working well, let's just
// have this screen trigger the dialog or embed the same widgets.
// However, the user asked to "make a new setting page", so a full screen is better.
// I'll copy the logic from the dialog into this screen for a seamless experience.
@@ -16,16 +15,18 @@ class SuppliesSettingsScreen extends ConsumerStatefulWidget {
const SuppliesSettingsScreen({super.key});
@override
ConsumerState<SuppliesSettingsScreen> createState() => _SuppliesSettingsScreenState();
ConsumerState<SuppliesSettingsScreen> createState() =>
_SuppliesSettingsScreenState();
}
class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen> {
class _SuppliesSettingsScreenState
extends ConsumerState<SuppliesSettingsScreen> {
bool _isTrackingEnabled = false;
int _typicalFlow = 2;
int _typicalFlow = 2;
bool _isAutoInventoryEnabled = true;
bool _showPadTimerMinutes = true;
bool _showPadTimerSeconds = false;
// Inventory
List<SupplyItem> _supplies = [];
int _lowInventoryThreshold = 5;
@@ -41,7 +42,7 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
_lowInventoryThreshold = user.lowInventoryThreshold;
_showPadTimerMinutes = user.showPadTimerMinutes;
_showPadTimerSeconds = user.showPadTimerSeconds;
// Load supplies
if (user.padSupplies != null) {
_supplies = List.from(user.padSupplies!);
@@ -65,19 +66,21 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
padInventoryCount: totalCount,
lowInventoryThreshold: _lowInventoryThreshold,
);
await ref.read(userProfileProvider.notifier).updateProfile(updatedProfile);
await ref
.read(userProfileProvider.notifier)
.updateProfile(updatedProfile);
// Check for Low Supply Alert
if (updatedProfile.notifyLowSupply &&
if (updatedProfile.notifyLowSupply &&
totalCount <= updatedProfile.lowInventoryThreshold) {
NotificationService().showLocalNotification(
id: 2001,
title: 'Low Pad Supply',
body: 'Your inventory is low ($totalCount left). Time to restock!',
);
NotificationService().showLocalNotification(
id: 2001,
title: 'Low Pad Supply',
body: 'Your inventory is low ($totalCount left). Time to restock!',
);
}
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Preferences saved')),
@@ -121,7 +124,7 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Toggle
// Toggle
Row(
children: [
Expanded(
@@ -137,14 +140,14 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
Switch(
value: _isTrackingEnabled,
onChanged: (val) => setState(() => _isTrackingEnabled = val),
activeColor: AppColors.menstrualPhase,
activeThumbColor: AppColors.menstrualPhase,
),
],
),
if (_isTrackingEnabled) ...[
const Divider(height: 32),
// Inventory Section
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -161,7 +164,8 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
onPressed: () => _addOrEditSupply(),
icon: const Icon(Icons.add),
label: const Text('Add Item'),
style: TextButton.styleFrom(foregroundColor: AppColors.menstrualPhase),
style: TextButton.styleFrom(
foregroundColor: AppColors.menstrualPhase),
),
],
),
@@ -170,7 +174,7 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.1),
color: Colors.grey.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Center(
@@ -193,10 +197,12 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
tileColor: Theme.of(context).cardTheme.color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(color: Colors.black.withOpacity(0.05)),
side: BorderSide(
color: Colors.black.withValues(alpha: 0.05)),
),
leading: CircleAvatar(
backgroundColor: AppColors.menstrualPhase.withOpacity(0.1),
backgroundColor:
AppColors.menstrualPhase.withValues(alpha: 0.1),
child: Text(
item.count.toString(),
style: GoogleFonts.outfit(
@@ -205,10 +211,14 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
),
),
),
title: Text(item.brand, style: GoogleFonts.outfit(fontWeight: FontWeight.w600)),
subtitle: Text(item.type.label, style: GoogleFonts.outfit(fontSize: 12)),
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),
icon:
const Icon(Icons.delete_outline, color: Colors.red),
onPressed: () {
setState(() {
_supplies.removeAt(index);
@@ -221,7 +231,7 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
),
const Divider(height: 32),
// Typical Flow
Text(
'Typical Flow Intensity',
@@ -234,7 +244,9 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
const SizedBox(height: 8),
Row(
children: [
Text('Light', style: GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray)),
Text('Light',
style: GoogleFonts.outfit(
fontSize: 12, color: AppColors.warmGray)),
Expanded(
child: Slider(
value: _typicalFlow.toDouble(),
@@ -242,42 +254,45 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
max: 5,
divisions: 4,
activeColor: AppColors.menstrualPhase,
onChanged: (val) => setState(() => _typicalFlow = val.round()),
onChanged: (val) =>
setState(() => _typicalFlow = val.round()),
),
),
Text('Heavy', style: GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray)),
Text('Heavy',
style: GoogleFonts.outfit(
fontSize: 12, color: AppColors.warmGray)),
],
),
Center(
child: Text(
'$_typicalFlow/5',
style: GoogleFonts.outfit(
fontWeight: FontWeight.bold,
color: AppColors.menstrualPhase
)
),
child: Text('$_typicalFlow/5',
style: GoogleFonts.outfit(
fontWeight: FontWeight.bold,
color: AppColors.menstrualPhase)),
),
const SizedBox(height: 24),
// Auto Deduct Toggle
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(
'Auto-deduct on Log',
style: GoogleFonts.outfit(fontWeight: FontWeight.w500, color: AppColors.charcoal),
),
subtitle: Text(
'Reduce count when you log a pad',
style: GoogleFonts.outfit(fontSize: 12, color: AppColors.warmGray),
),
value: _isAutoInventoryEnabled,
onChanged: (val) => setState(() => _isAutoInventoryEnabled = val),
activeColor: AppColors.menstrualPhase,
contentPadding: EdgeInsets.zero,
title: Text(
'Auto-deduct on Log',
style: GoogleFonts.outfit(
fontWeight: FontWeight.w500, color: AppColors.charcoal),
),
subtitle: Text(
'Reduce count when you log a pad',
style: GoogleFonts.outfit(
fontSize: 12, color: AppColors.warmGray),
),
value: _isAutoInventoryEnabled,
onChanged: (val) =>
setState(() => _isAutoInventoryEnabled = val),
activeThumbColor: AppColors.menstrualPhase,
),
const Divider(height: 32),
Text(
'Timer Display Settings',
style: GoogleFonts.outfit(
@@ -289,35 +304,39 @@ class _SuppliesSettingsScreenState extends ConsumerState<SuppliesSettingsScreen>
const SizedBox(height: 8),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(
'Show Minutes',
style: GoogleFonts.outfit(fontWeight: FontWeight.w500, color: AppColors.charcoal),
),
value: _showPadTimerMinutes,
onChanged: (val) {
setState(() {
_showPadTimerMinutes = val;
if (!val) {
_showPadTimerSeconds = false;
}
});
},
activeColor: AppColors.menstrualPhase,
contentPadding: EdgeInsets.zero,
title: Text(
'Show Minutes',
style: GoogleFonts.outfit(
fontWeight: FontWeight.w500, color: AppColors.charcoal),
),
value: _showPadTimerMinutes,
onChanged: (val) {
setState(() {
_showPadTimerMinutes = val;
if (!val) {
_showPadTimerSeconds = false;
}
});
},
activeThumbColor: AppColors.menstrualPhase,
),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text(
'Show Seconds',
style: GoogleFonts.outfit(
fontWeight: FontWeight.w500,
color: _showPadTimerMinutes ? AppColors.charcoal : AppColors.warmGray
),
),
value: _showPadTimerSeconds,
onChanged: _showPadTimerMinutes ? (val) => setState(() => _showPadTimerSeconds = val) : null,
activeColor: AppColors.menstrualPhase,
contentPadding: EdgeInsets.zero,
title: Text(
'Show Seconds',
style: GoogleFonts.outfit(
fontWeight: FontWeight.w500,
color: _showPadTimerMinutes
? AppColors.charcoal
: AppColors.warmGray),
),
value: _showPadTimerSeconds,
onChanged: _showPadTimerMinutes
? (val) => setState(() => _showPadTimerSeconds = val)
: null,
activeThumbColor: AppColors.menstrualPhase,
),
],
],
@@ -345,11 +364,12 @@ class _SupplyDialogState extends State<_SupplyDialog> {
@override
void initState() {
super.initState();
_brandController = TextEditingController(text: widget.initialItem?.brand ?? '');
_brandController =
TextEditingController(text: widget.initialItem?.brand ?? '');
_type = widget.initialItem?.type ?? PadType.regular;
_count = widget.initialItem?.count ?? 0;
}
@override
void dispose() {
_brandController.dispose();
@@ -371,11 +391,13 @@ class _SupplyDialogState extends State<_SupplyDialog> {
),
const SizedBox(height: 16),
DropdownButtonFormField<PadType>(
value: _type,
items: PadType.values.map((t) => DropdownMenuItem(
value: t,
child: Text(t.label),
)).toList(),
initialValue: _type,
items: PadType.values
.map((t) => DropdownMenuItem(
value: t,
child: Text(t.label),
))
.toList(),
onChanged: (val) => setState(() => _type = val!),
decoration: const InputDecoration(labelText: 'Type'),
),
@@ -383,14 +405,18 @@ class _SupplyDialogState extends State<_SupplyDialog> {
TextField(
keyboardType: TextInputType.number,
decoration: const InputDecoration(labelText: 'Quantity'),
controller: TextEditingController(text: _count.toString()), // Hacky for demo, binding needed properly
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')),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel')),
ElevatedButton(
onPressed: () {
if (_brandController.text.isEmpty) return;