This commit is contained in:
2025-12-30 23:20:50 -06:00
parent 9f8eab4a31
commit ec923c906e
26 changed files with 2234 additions and 53 deletions

View File

@@ -0,0 +1,162 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../models/user_profile.dart';
import '../../providers/user_provider.dart';
import '../../theme/app_theme.dart';
class AppearanceScreen extends ConsumerWidget {
const AppearanceScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final userProfile = ref.watch(userProfileProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Appearance'),
),
body: userProfile == null
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16.0),
children: [
_buildThemeModeSelector(context, ref, userProfile.themeMode),
const SizedBox(height: 24),
_buildAccentColorSelector(
context, ref, userProfile.accentColor, AppColors.sageGreen),
const SizedBox(height: 32),
_buildRelationshipStatusSelector(context, ref, userProfile.relationshipStatus),
],
),
);
}
Widget _buildThemeModeSelector(
BuildContext context, WidgetRef ref, AppThemeMode currentMode) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Theme Mode',
style: Theme.of(context).textTheme.titleLarge,
),
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),
)
),
],
);
}
Widget _buildAccentColorSelector(BuildContext context, WidgetRef ref,
String currentAccent) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Accent Color',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
Wrap(
spacing: 16,
runSpacing: 16,
children: [
GestureDetector(
onTap: () {
ref
.read(userProfileProvider.notifier)
.updateAccentColor('0xFFA8C5A8');
},
child: Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: AppColors.sageGreen,
shape: BoxShape.circle,
border: Border.all(
color:
Theme.of(context).colorScheme.primary, // Assuming currentAccent is sageGreen
width: 3,
),
),
child: const Icon(Icons.check, color: Colors.white),
),
),
],
),
],
);
}
Widget _buildRelationshipStatusSelector(
BuildContext context, WidgetRef ref, RelationshipStatus currentStatus) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Relationship Status',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
SegmentedButton<RelationshipStatus>(
segments: const [
ButtonSegment(
value: RelationshipStatus.single,
label: Text('Single'),
icon: Icon(Icons.person_outline),
),
ButtonSegment(
value: RelationshipStatus.engaged,
label: Text('Engaged'),
icon: Icon(Icons.favorite_border),
),
ButtonSegment(
value: RelationshipStatus.married,
label: Text('Married'),
icon: Icon(Icons.favorite),
),
],
selected: {currentStatus},
onSelectionChanged: (Set<RelationshipStatus> newSelection) {
if (newSelection.isNotEmpty) {
ref
.read(userProfileProvider.notifier)
.updateRelationshipStatus(newSelection.first);
}
},
style: SegmentedButton.styleFrom(
fixedSize: const Size.fromHeight(48),
)
),
],
);
}
}

View File

@@ -0,0 +1,240 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:collection/collection.dart';
import '../../models/cycle_entry.dart';
import '../../providers/user_provider.dart';
class CycleHistoryScreen extends ConsumerWidget {
const CycleHistoryScreen({super.key});
void _showDeleteAllDialog(BuildContext context, WidgetRef ref) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Delete All History?'),
content: const Text(
'This will permanently delete all cycle entries. This action cannot be undone.'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
ref.read(cycleEntriesProvider.notifier).clearEntries();
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('All cycle history has been deleted.')),
);
},
child: const Text('Delete All', style: TextStyle(color: Colors.red)),
),
],
),
);
}
void _showDeleteMonthDialog(BuildContext context, WidgetRef ref) {
showDialog(
context: context,
builder: (context) => const _DeleteMonthDialog(),
);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final entries = ref.watch(cycleEntriesProvider);
final groupedEntries = groupBy(
entries,
(CycleEntry entry) => DateFormat('MMMM yyyy').format(entry.date),
);
return Scaffold(
appBar: AppBar(
title: const Text('Cycle History'),
actions: [
if (entries.isNotEmpty)
PopupMenuButton<String>(
onSelected: (value) {
if (value == 'delete_all') {
_showDeleteAllDialog(context, ref);
} else if (value == 'delete_month') {
_showDeleteMonthDialog(context, ref);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'delete_month',
child: Text('Delete by Month'),
),
const PopupMenuItem<String>(
value: 'delete_all',
child: Text('Delete All Data'),
),
],
),
],
),
body: entries.isEmpty
? Center(
child: Text(
'No cycle history found.',
style: Theme.of(context).textTheme.bodyLarge,
),
)
: ListView.builder(
itemCount: groupedEntries.keys.length,
itemBuilder: (context, index) {
final month = groupedEntries.keys.elementAt(index);
final monthEntries = groupedEntries[month]!;
return ExpansionTile(
title: Text(month, style: Theme.of(context).textTheme.titleLarge),
initiallyExpanded: index == 0,
children: monthEntries.map((entry) {
return Dismissible(
key: Key(entry.id),
direction: DismissDirection.endToStart,
onDismissed: (direction) {
ref.read(cycleEntriesProvider.notifier).deleteEntry(entry.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Entry for ${DateFormat.yMMMd().format(entry.date)} deleted.')),
);
},
background: Container(
color: Colors.red,
alignment: Alignment.centerRight,
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: const Icon(Icons.delete, color: Colors.white),
),
child: ListTile(
title: Text(DateFormat.yMMMMEEEEd().format(entry.date)),
subtitle: Text(_buildEntrySummary(entry)),
isThreeLine: true,
),
);
}).toList(),
);
},
),
);
}
String _buildEntrySummary(CycleEntry entry) {
final summary = <String>[];
if (entry.isPeriodDay) {
summary.add('Period');
}
if (entry.mood != null) {
summary.add('Mood: ${entry.mood!.label}');
}
if (entry.symptomCount > 0) {
summary.add('${entry.symptomCount} symptom(s)');
}
if (entry.notes != null && entry.notes!.isNotEmpty) {
summary.add('Note');
}
if (summary.isEmpty) {
return 'No specific data logged.';
}
return summary.join('');
}
}
class _DeleteMonthDialog extends ConsumerStatefulWidget {
const _DeleteMonthDialog();
@override
ConsumerState<_DeleteMonthDialog> createState() => _DeleteMonthDialogState();
}
class _DeleteMonthDialogState extends ConsumerState<_DeleteMonthDialog> {
late int _selectedYear;
late int _selectedMonth;
@override
void initState() {
super.initState();
final now = DateTime.now();
_selectedYear = now.year;
_selectedMonth = now.month;
}
@override
Widget build(BuildContext context) {
final years =
List.generate(5, (index) => DateTime.now().year - index);
final months = List.generate(12, (index) => index + 1);
return AlertDialog(
title: const Text('Delete by Month'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Select a month and year to delete all entries from.'),
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DropdownButton<int>(
value: _selectedMonth,
items: months.map((month) => DropdownMenuItem(
value: month,
child: Text(DateFormat('MMMM').format(DateTime(0, month))),
))
.toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_selectedMonth = value;
});
}
},
),
const SizedBox(width: 16),
DropdownButton<int>(
value: _selectedYear,
items: years
.map((year) => DropdownMenuItem(
value: year,
child: Text(year.toString()),
))
.toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_selectedYear = value;
});
}
},
),
],
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
ref
.read(cycleEntriesProvider.notifier)
.deleteEntriesForMonth(_selectedYear, _selectedMonth);
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Deleted entries for ${DateFormat('MMMM yyyy').format(DateTime(0, _selectedMonth))}.')),
);
},
child: const Text('Delete', style: TextStyle(color: Colors.red)),
),
],
);
}
}

View File

@@ -0,0 +1,143 @@
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 {
const CycleSettingsScreen({super.key});
@override
ConsumerState<CycleSettingsScreen> createState() =>
_CycleSettingsScreenState();
}
class _CycleSettingsScreenState extends ConsumerState<CycleSettingsScreen> {
final _formKey = GlobalKey<FormState>();
late TextEditingController _cycleLengthController;
late TextEditingController _periodLengthController;
DateTime? _lastPeriodStartDate;
bool _isIrregularCycle = false;
@override
void initState() {
super.initState();
final userProfile = ref.read(userProfileProvider);
_cycleLengthController = TextEditingController(
text: userProfile?.averageCycleLength.toString() ?? '28');
_periodLengthController = TextEditingController(
text: userProfile?.averagePeriodLength.toString() ?? '5');
_lastPeriodStartDate = userProfile?.lastPeriodStartDate;
_isIrregularCycle = userProfile?.isIrregularCycle ?? false;
}
@override
void dispose() {
_cycleLengthController.dispose();
_periodLengthController.dispose();
super.dispose();
}
void _saveSettings() {
if (_formKey.currentState!.validate()) {
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,
lastPeriodStartDate: _lastPeriodStartDate,
isIrregularCycle: _isIrregularCycle,
);
ref.read(userProfileProvider.notifier).updateProfile(updatedProfile);
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cycle settings saved!')),
);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cycle Settings'),
),
body: Form(
key: _formKey,
child: ListView(
padding: const EdgeInsets.all(24.0),
children: [
TextFormField(
controller: _cycleLengthController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Average Cycle Length (days)',
hintText: 'e.g., 28',
),
validator: (value) {
if (value == null || int.tryParse(value) == null) {
return 'Please enter a valid number';
}
return null;
},
),
const SizedBox(height: 24),
TextFormField(
controller: _periodLengthController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Average Period Length (days)',
hintText: 'e.g., 5',
),
validator: (value) {
if (value == null || int.tryParse(value) == null) {
return 'Please enter a valid number';
}
return null;
},
),
const SizedBox(height: 24),
ListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Last Period Start Date'),
subtitle: Text(_lastPeriodStartDate == null
? 'Not set'
: DateFormat.yMMMMd().format(_lastPeriodStartDate!)),
trailing: const Icon(Icons.calendar_today),
onTap: () async {
final pickedDate = await showDatePicker(
context: context,
initialDate: _lastPeriodStartDate ?? DateTime.now(),
firstDate: DateTime(DateTime.now().year - 1),
lastDate: DateTime.now(),
);
if (pickedDate != null) {
setState(() {
_lastPeriodStartDate = pickedDate;
});
}
},
),
const Divider(),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('My cycle is irregular'),
value: _isIrregularCycle,
onChanged: (value) {
setState(() {
_isIrregularCycle = value;
});
},
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: _saveSettings,
child: const Text('Save Settings'),
)
],
),
),
);
}
}

View File

@@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../providers/user_provider.dart';
import '../../services/pdf_service.dart';
import '../../services/ics_service.dart';
class ExportDataScreen extends ConsumerWidget {
const ExportDataScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final userProfile = ref.watch(userProfileProvider);
final cycleEntries = ref.watch(cycleEntriesProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Export Data'),
),
body: userProfile == null
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16.0),
children: [
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.'),
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!')),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to generate PDF: $e')),
);
}
},
),
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.'),
trailing: const Icon(Icons.chevron_right),
onTap: () async {
try {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Generating ICS file...')),
);
await IcsService.generateCycleCalendar(cycleEntries);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('ICS file generated successfully!')),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to generate ICS file: $e')),
);
}
},
),
],
),
);
}
}

View File

@@ -0,0 +1,141 @@
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';
class PrivacySettingsScreen extends ConsumerStatefulWidget {
const PrivacySettingsScreen({super.key});
@override
ConsumerState<PrivacySettingsScreen> createState() =>
_PrivacySettingsScreenState();
}
class _PrivacySettingsScreenState extends ConsumerState<PrivacySettingsScreen> {
bool _hasPermissions = false;
final HealthService _healthService = HealthService();
@override
void initState() {
super.initState();
_checkPermissions();
}
Future<void> _checkPermissions() async {
final hasPermissions = await _healthService.hasPermissions(_healthService.menstruationDataTypes);
setState(() {
_hasPermissions = hasPermissions;
});
}
Future<void> _requestPermissions() async {
final authorized = await _healthService.requestAuthorization(_healthService.menstruationDataTypes);
if (authorized) {
_hasPermissions = true;
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.')),
);
}
setState(() {}); // Rebuild to update UI
}
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) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cannot sync without health app permissions.')),
);
}
return;
}
_hasPermissions = true;
}
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Syncing period data...')),
);
}
final userProfile = ref.read(userProfileProvider);
final cycleEntries = ref.read(cycleEntriesProvider);
if (userProfile != null) {
final success = await _healthService.writeMenstruationData(cycleEntries);
if (mounted) {
if (success) {
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.')),
);
}
}
}
} 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.')),
);
}
}
setState(() {}); // Rebuild to update UI
}
@override
Widget build(BuildContext context) {
// This value would ideally come from userProfile.syncPeriodToHealth
bool syncPeriodToHealth = _hasPermissions;
return Scaffold(
appBar: AppBar(
title: const Text('Privacy Settings'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
children: [
ListTile(
title: const Text('Health App Integration'),
subtitle: _hasPermissions
? const Text('Connected to Health App. Period data can be synced.')
: 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.'),
value: syncPeriodToHealth,
onChanged: (value) async {
if (value) {
await _syncPeriodDays(true);
} else {
await _syncPeriodDays(false);
}
setState(() {
syncPeriodToHealth = value; // Update local state for toggle
});
},
enabled: _hasPermissions, // Only enable if connected
),
// TODO: Add more privacy settings if needed
],
),
);
}
}

View File

@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../models/user_profile.dart';
import '../../providers/user_provider.dart';
class SharingSettingsScreen extends ConsumerWidget {
const SharingSettingsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final userProfile = ref.watch(userProfileProvider);
if (userProfile == null) {
return Scaffold(
appBar: AppBar(
title: const Text('Sharing Settings'),
),
body: const Center(child: CircularProgressIndicator()),
);
}
return Scaffold(
appBar: AppBar(
title: const Text('Sharing Settings'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
children: [
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));
},
),
],
),
);
}
}