Enhance Pad Tracking with new Flow and Supply logic

This commit is contained in:
2026-01-09 13:35:07 -06:00
parent 24ffac2415
commit dc6bcad83f
17 changed files with 765 additions and 171 deletions

View File

@@ -23,8 +23,8 @@ class LogScreen extends ConsumerStatefulWidget {
class _LogScreenState extends ConsumerState<LogScreen> {
late DateTime _selectedDate;
String? _existingEntryId;
bool _isPeriodDay = false;
bool _isSpotting = false;
bool? _isPeriodDay;
bool? _isSpotting;
FlowIntensity? _flowIntensity;
MoodLevel? _mood;
int? _energyLevel;
@@ -45,12 +45,12 @@ class _LogScreenState extends ConsumerState<LogScreen> {
TextEditingController();
// Intimacy tracking
bool _hadIntimacy = false;
bool? _hadIntimacy;
bool?
_intimacyProtected; // null = no selection, true = protected, false = unprotected
// Pantyliner / Supply tracking
bool _usedPantyliner = false; // Used for "Did you use supplies?"
bool? _usedPantyliner; // Used for "Did you use supplies?"
int _pantylinerCount = 0;
int? _selectedSupplyIndex; // Index of selected supply from inventory
@@ -126,10 +126,10 @@ class _LogScreenState extends ConsumerState<LogScreen> {
final entry = CycleEntry(
id: _existingEntryId ?? const Uuid().v4(),
date: _selectedDate,
isPeriodDay: _isPeriodDay,
flowIntensity: _isPeriodDay
isPeriodDay: _isPeriodDay ?? false,
flowIntensity: _isPeriodDay == true
? _flowIntensity
: (_isSpotting ? FlowIntensity.spotting : null),
: (_isSpotting == true ? FlowIntensity.spotting : null),
mood: _mood,
energyLevel: _energyLevel,
crampIntensity: _crampIntensity > 0 ? _crampIntensity : null,
@@ -146,10 +146,10 @@ class _LogScreenState extends ConsumerState<LogScreen> {
notes: _notesController.text.isNotEmpty ? _notesController.text : null,
cravings: cravings,
husbandNotes: _husbandNotes,
hadIntimacy: _hadIntimacy,
intimacyProtected: _hadIntimacy ? _intimacyProtected : null,
usedPantyliner: _usedPantyliner,
pantylinerCount: _usedPantyliner ? _pantylinerCount : 0,
hadIntimacy: _hadIntimacy ?? false,
intimacyProtected: _hadIntimacy == true ? _intimacyProtected : null,
usedPantyliner: _usedPantyliner ?? false,
pantylinerCount: _usedPantyliner == true ? _pantylinerCount : 0,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
@@ -161,7 +161,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
}
// Trigger Notification if Period Start
if (_isPeriodDay &&
if (_isPeriodDay == true &&
ref.read(userProfileProvider)?.notifyPeriodStart == true) {
final entries = ref.read(cycleEntriesProvider);
final yesterday = _selectedDate.subtract(const Duration(days: 1));
@@ -198,8 +198,8 @@ class _LogScreenState extends ConsumerState<LogScreen> {
void _resetForm() {
setState(() {
_existingEntryId = null;
_isPeriodDay = false;
_isSpotting = false;
_isPeriodDay = null;
_isSpotting = null;
_flowIntensity = null;
_mood = null;
_energyLevel = 3;
@@ -217,9 +217,9 @@ class _LogScreenState extends ConsumerState<LogScreen> {
_notesController.clear();
_cravingsController.clear();
_husbandNotes = null;
_hadIntimacy = false;
_hadIntimacy = null;
_intimacyProtected = null;
_usedPantyliner = false;
_usedPantyliner = null;
_pantylinerCount = 0;
});
}
@@ -321,7 +321,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
),
// Are you spotting? (only if NOT period day)
if (!_isPeriodDay) ...[
if (_isPeriodDay != true) ...[
const SizedBox(height: 16),
_buildSectionCard(
context,
@@ -350,7 +350,8 @@ class _LogScreenState extends ConsumerState<LogScreen> {
],
// Still on Period? (If predicted but toggle is NO)
if (!_isPeriodDay && _shouldShowPeriodCompletionPrompt()) ...[
if (_isPeriodDay == false &&
_shouldShowPeriodCompletionPrompt()) ...[
const SizedBox(height: 16),
_buildSectionCard(
context,
@@ -406,7 +407,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
],
// Flow Intensity (only if period day)
if (_isPeriodDay) ...[
if (_isPeriodDay == true) ...[
const SizedBox(height: 16),
_buildSectionCard(
context,
@@ -474,7 +475,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
context,
MaterialPageRoute(
builder: (context) => PadTrackerScreen(
isSpotting: _isSpotting,
isSpotting: _isSpotting ?? false,
initialFlow: _flowIntensity,
),
),
@@ -515,7 +516,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
),
],
),
if (_usedPantyliner) ...[
if (_usedPantyliner == true) ...[
const SizedBox(height: 12),
if (userProfile?.padSupplies?.isNotEmpty == true) ...[
Text(
@@ -844,15 +845,17 @@ class _LogScreenState extends ConsumerState<LogScreen> {
SwitchListTile(
title: Text('Had Intimacy Today',
style: GoogleFonts.outfit(fontSize: 14)),
value: _hadIntimacy,
value: _hadIntimacy ?? false,
onChanged: (val) => setState(() {
_hadIntimacy = val;
if (!val) _intimacyProtected = null;
if (!val) {
_intimacyProtected = null;
}
}),
activeThumbColor: AppColors.sageGreen,
contentPadding: EdgeInsets.zero,
),
if (_hadIntimacy) ...[
if (_hadIntimacy == true) ...[
const SizedBox(height: 8),
Text('Protection:',
style: GoogleFonts.outfit(
@@ -1022,7 +1025,7 @@ class _LogScreenState extends ConsumerState<LogScreen> {
}
Widget _buildYesNoControl(BuildContext context,
{required bool value,
{required bool? value,
required ValueChanged<bool> onChanged,
required Color activeColor}) {
final theme = Theme.of(context);
@@ -1037,24 +1040,24 @@ class _LogScreenState extends ConsumerState<LogScreen> {
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: !value
color: value == false
? theme.colorScheme.error
.withValues(alpha: isDark ? 0.3 : 0.2)
: theme.colorScheme.surfaceContainerHighest
.withValues(alpha: 0.3),
borderRadius:
const BorderRadius.horizontal(left: Radius.circular(8)),
border: !value
border: value == false
? Border.all(color: theme.colorScheme.error)
: Border.all(color: Colors.transparent),
),
child: Text(
'No',
style: GoogleFonts.outfit(
color: !value
color: value == false
? theme.colorScheme.error
: theme.colorScheme.onSurfaceVariant,
fontWeight: !value ? FontWeight.w600 : FontWeight.w400,
fontWeight: value == false ? FontWeight.w600 : FontWeight.w400,
),
),
),
@@ -1065,21 +1068,23 @@ class _LogScreenState extends ConsumerState<LogScreen> {
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: value
color: value == true
? activeColor.withValues(alpha: isDark ? 0.3 : 0.2)
: theme.colorScheme.surfaceContainerHighest
.withValues(alpha: 0.3),
borderRadius:
const BorderRadius.horizontal(right: Radius.circular(8)),
border: value
border: value == true
? Border.all(color: activeColor)
: Border.all(color: Colors.transparent),
),
child: Text(
'Yes',
style: GoogleFonts.outfit(
color: value ? activeColor : theme.colorScheme.onSurfaceVariant,
fontWeight: value ? FontWeight.w600 : FontWeight.w400,
color: value == true
? activeColor
: theme.colorScheme.onSurfaceVariant,
fontWeight: value == true ? FontWeight.w600 : FontWeight.w400,
),
),
),