Files
Tracker/lib/models/user_profile.dart
Sterlen b4b2bfe749 feat: Implement husband features and fix iOS Safari web startup
Implement initial features for husband's companion app, including mock data
service and husband notes screen. Refactor scripture and cycle services
for improved stability and testability. Address iOS Safari web app
startup issue by removing deprecated initialization.

- Implemented MockDataService and HusbandNotesScreen.
- Converted _DashboardTab and DevotionalScreen to StatefulWidgets for robust
  scripture provider initialization.
- Refactored CycleService to use immutable CycleInfo class, reducing UI rebuilds.
- Removed deprecated window.flutterConfiguration from index.html, resolving
  Flutter web app startup failure on iOS Safari.
- Updated and fixed related tests.
2025-12-26 22:40:52 -06:00

222 lines
5.1 KiB
Dart

import 'package:hive/hive.dart';
part 'user_profile.g.dart';
/// User's relationship status
@HiveType(typeId: 0)
enum RelationshipStatus {
@HiveField(0)
single,
@HiveField(1)
engaged,
@HiveField(2)
married,
}
/// Fertility tracking goal for married users
@HiveType(typeId: 1)
enum FertilityGoal {
@HiveField(0)
tryingToConceive, // TTC
@HiveField(1)
tryingToAvoid, // TTA - NFP
@HiveField(2)
justTracking,
}
@HiveType(typeId: 9)
enum BibleTranslation {
@HiveField(0)
esv,
@HiveField(1)
niv,
@HiveField(2)
nkjv,
@HiveField(3)
nlt,
@HiveField(4)
nasb,
@HiveField(5)
kjv,
@HiveField(6)
msg,
}
/// User profile model
@HiveType(typeId: 2)
class UserProfile extends HiveObject {
@HiveField(0)
String id;
@HiveField(1)
String name;
@HiveField(2)
RelationshipStatus relationshipStatus;
@HiveField(3)
FertilityGoal? fertilityGoal;
@HiveField(4)
int averageCycleLength;
@HiveField(5)
int averagePeriodLength;
@HiveField(6)
DateTime? lastPeriodStartDate;
@HiveField(7)
bool notificationsEnabled;
@HiveField(8)
String? devotionalTime; // HH:mm format
@HiveField(9)
bool hasCompletedOnboarding;
@HiveField(10)
DateTime createdAt;
@HiveField(11)
DateTime updatedAt;
@HiveField(12)
String? partnerName; // For married users
@HiveField(14, defaultValue: UserRole.wife)
UserRole role;
@HiveField(15, defaultValue: false)
bool isIrregularCycle;
@HiveField(16, defaultValue: BibleTranslation.esv)
BibleTranslation bibleTranslation;
@HiveField(17)
List<String>? favoriteFoods;
@HiveField(18, defaultValue: false)
bool isDataShared;
UserProfile({
required this.id,
required this.name,
this.relationshipStatus = RelationshipStatus.single,
this.fertilityGoal,
this.averageCycleLength = 28,
this.averagePeriodLength = 5,
this.lastPeriodStartDate,
this.notificationsEnabled = true,
this.devotionalTime,
this.hasCompletedOnboarding = false,
required this.createdAt,
required this.updatedAt,
this.partnerName,
this.role = UserRole.wife,
this.isIrregularCycle = false,
this.bibleTranslation = BibleTranslation.esv,
this.favoriteFoods,
this.isDataShared = false,
});
/// Check if user is married
bool get isMarried => relationshipStatus == RelationshipStatus.married;
/// Check if user is trying to conceive
bool get isTTC => fertilityGoal == FertilityGoal.tryingToConceive;
/// Check if user is practicing NFP
bool get isNFP => fertilityGoal == FertilityGoal.tryingToAvoid;
/// Check if user is husband
bool get isHusband => role == UserRole.husband;
/// Should show fertility content
bool get showFertilityContent =>
!isHusband &&
isMarried &&
fertilityGoal != FertilityGoal.justTracking &&
fertilityGoal != null;
/// Should show intimacy recommendations
bool get showIntimacyContent => isMarried;
/// Copy with updated fields
UserProfile copyWith({
String? id,
String? name,
RelationshipStatus? relationshipStatus,
FertilityGoal? fertilityGoal,
int? averageCycleLength,
int? averagePeriodLength,
DateTime? lastPeriodStartDate,
bool? notificationsEnabled,
String? devotionalTime,
bool? hasCompletedOnboarding,
DateTime? createdAt,
DateTime? updatedAt,
String? partnerName,
UserRole? role,
bool? isIrregularCycle,
BibleTranslation? bibleTranslation,
List<String>? favoriteFoods,
bool? isDataShared,
}) {
return UserProfile(
id: id ?? this.id,
name: name ?? this.name,
relationshipStatus: relationshipStatus ?? this.relationshipStatus,
fertilityGoal: fertilityGoal ?? this.fertilityGoal,
averageCycleLength: averageCycleLength ?? this.averageCycleLength,
averagePeriodLength: averagePeriodLength ?? this.averagePeriodLength,
lastPeriodStartDate: lastPeriodStartDate ?? this.lastPeriodStartDate,
notificationsEnabled: notificationsEnabled ?? this.notificationsEnabled,
devotionalTime: devotionalTime ?? this.devotionalTime,
hasCompletedOnboarding:
hasCompletedOnboarding ?? this.hasCompletedOnboarding,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? DateTime.now(),
partnerName: partnerName ?? this.partnerName,
role: role ?? this.role,
isIrregularCycle: isIrregularCycle ?? this.isIrregularCycle,
bibleTranslation: bibleTranslation ?? this.bibleTranslation,
favoriteFoods: favoriteFoods ?? this.favoriteFoods,
isDataShared: isDataShared ?? this.isDataShared,
);
}
}
extension BibleTranslationExtension on BibleTranslation {
String get label {
switch (this) {
case BibleTranslation.esv:
return 'ESV';
case BibleTranslation.niv:
return 'NIV';
case BibleTranslation.nkjv:
return 'NKJV';
case BibleTranslation.nlt:
return 'NLT';
case BibleTranslation.nasb:
return 'NASB';
case BibleTranslation.kjv:
return 'KJV';
case BibleTranslation.msg:
return 'MSG';
}
}
}
@HiveType(typeId: 8)
enum UserRole {
@HiveField(0)
wife,
@HiveField(1)
husband,
}