Implement husband-wife connection dialogue and theme support for learn articles

This commit is contained in:
2026-01-05 17:09:15 -06:00
parent 02d25d0cc7
commit 96655f9a74
36 changed files with 3849 additions and 819 deletions

View File

@@ -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'),
),
],
);
}
}