Enhance Pad Tracking with new Flow and Supply logic
This commit is contained in:
@@ -2,10 +2,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import '../models/user_profile.dart';
|
||||
import '../models/cycle_entry.dart';
|
||||
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../services/cycle_service.dart';
|
||||
|
||||
/// Provider for the user profile
|
||||
final userProfileProvider = StateNotifierProvider<UserProfileNotifier, UserProfile?>((ref) {
|
||||
final userProfileProvider =
|
||||
StateNotifierProvider<UserProfileNotifier, UserProfile?>((ref) {
|
||||
return UserProfileNotifier();
|
||||
});
|
||||
|
||||
@@ -38,9 +41,11 @@ class UserProfileNotifier extends StateNotifier<UserProfile?> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateRelationshipStatus(RelationshipStatus relationshipStatus) async {
|
||||
Future<void> updateRelationshipStatus(
|
||||
RelationshipStatus relationshipStatus) async {
|
||||
if (state != null) {
|
||||
await updateProfile(state!.copyWith(relationshipStatus: relationshipStatus));
|
||||
await updateProfile(
|
||||
state!.copyWith(relationshipStatus: relationshipStatus));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +57,8 @@ class UserProfileNotifier extends StateNotifier<UserProfile?> {
|
||||
}
|
||||
|
||||
/// Provider for cycle entries
|
||||
final cycleEntriesProvider = StateNotifierProvider<CycleEntriesNotifier, List<CycleEntry>>((ref) {
|
||||
final cycleEntriesProvider =
|
||||
StateNotifierProvider<CycleEntriesNotifier, List<CycleEntry>>((ref) {
|
||||
return CycleEntriesNotifier();
|
||||
});
|
||||
|
||||
@@ -102,6 +108,56 @@ class CycleEntriesNotifier extends StateNotifier<List<CycleEntry>> {
|
||||
await box.clear();
|
||||
state = [];
|
||||
}
|
||||
|
||||
Future<void> generateExampleData(String userId) async {
|
||||
await clearEntries();
|
||||
final box = Hive.box<CycleEntry>('cycle_entries');
|
||||
final today = DateTime.now();
|
||||
|
||||
// Generate 3 past cycles (~28 days each)
|
||||
DateTime cycleStart = today.subtract(const Duration(days: 84)); // 3 * 28
|
||||
|
||||
while (cycleStart.isBefore(today)) {
|
||||
// Create Period (5 days)
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final date = cycleStart.add(Duration(days: i));
|
||||
if (date.isAfter(today)) break;
|
||||
|
||||
final isHeavy = i == 1 || i == 2;
|
||||
final entry = CycleEntry(
|
||||
id: const Uuid().v4(),
|
||||
date: date,
|
||||
isPeriodDay: true,
|
||||
flowIntensity: isHeavy ? FlowIntensity.heavy : FlowIntensity.medium,
|
||||
mood: i == 1 ? MoodLevel.sad : null,
|
||||
crampIntensity: i == 0 ? 3 : null,
|
||||
hasHeadache: i == 0,
|
||||
createdAt: date,
|
||||
updatedAt: date,
|
||||
);
|
||||
await box.put(entry.id, entry);
|
||||
}
|
||||
|
||||
// Add random ovulation symptoms near day 14
|
||||
final ovulationDay = cycleStart.add(const Duration(days: 14));
|
||||
if (ovulationDay.isBefore(today)) {
|
||||
final entry = CycleEntry(
|
||||
id: const Uuid().v4(),
|
||||
date: ovulationDay,
|
||||
isPeriodDay: false,
|
||||
energyLevel: 4, // High energy
|
||||
mood: MoodLevel.veryHappy,
|
||||
createdAt: ovulationDay,
|
||||
updatedAt: ovulationDay,
|
||||
);
|
||||
await box.put(entry.id, entry);
|
||||
}
|
||||
|
||||
cycleStart = cycleStart.add(const Duration(days: 28));
|
||||
}
|
||||
|
||||
_loadEntries();
|
||||
}
|
||||
}
|
||||
|
||||
/// Computed provider for current cycle info
|
||||
|
||||
Reference in New Issue
Block a user