119 lines
3.4 KiB
Dart
119 lines
3.4 KiB
Dart
import 'package:hive/hive.dart';
|
|
import '../services/level_calculator.dart';
|
|
|
|
part 'user_profile.g.dart';
|
|
|
|
@HiveType(typeId: 1)
|
|
class UserProfile extends HiveObject {
|
|
@HiveField(0)
|
|
// DEPRECATED: String? mbtiType;
|
|
// Hive indices must not be reused or reordered carelessly.
|
|
// Ideally we keep the index but ignore it, or just use the old index for new logic.
|
|
// The user review suggested: "Remove old fields... or unify".
|
|
// Since we already used new indices (6, 7) in the previous step and ran build_runner,
|
|
// keeping 6 and 7 is safer if we want to avoid migration issues with recently created data.
|
|
// But since this is dev, clean up is better.
|
|
// However, I will follow the user's advice to remove the old ones.
|
|
// I will comment them out to reserve the index if needed, or just remove.
|
|
// Let's remove them and their constructor args.
|
|
|
|
@HiveField(2)
|
|
String fontPreference; // "serif" or "sans"
|
|
|
|
@HiveField(3)
|
|
DateTime createdAt;
|
|
|
|
@HiveField(4)
|
|
DateTime? updatedAt;
|
|
|
|
@HiveField(5)
|
|
String displayMode; // "list" or "grid"
|
|
|
|
@HiveField(6)
|
|
String? mbti;
|
|
|
|
@HiveField(7)
|
|
DateTime? birthdate;
|
|
|
|
@HiveField(8)
|
|
String themeMode; // 'system', 'light', 'dark'
|
|
|
|
@HiveField(9, defaultValue: false)
|
|
bool isBusinessMode;
|
|
|
|
@HiveField(10, defaultValue: 3.0)
|
|
double defaultMarkup;
|
|
|
|
@HiveField(11, defaultValue: false)
|
|
bool hasCompletedOnboarding;
|
|
|
|
@HiveField(12)
|
|
String? nickname;
|
|
|
|
@HiveField(13)
|
|
String? gender; // 'male', 'female', 'other', null
|
|
|
|
@HiveField(14, defaultValue: 0)
|
|
int totalExp;
|
|
|
|
@HiveField(15, defaultValue: [])
|
|
List<String> unlockedBadges;
|
|
|
|
// Calculators
|
|
int get level => LevelCalculator.getLevel(totalExp);
|
|
String get title => LevelCalculator.getTitle(totalExp);
|
|
double get nextLevelProgress => LevelCalculator.getProgress(totalExp);
|
|
int get expToNextLevel => LevelCalculator.getExpToNextLevel(totalExp);
|
|
|
|
UserProfile({
|
|
this.fontPreference = 'sans',
|
|
this.displayMode = 'list',
|
|
required this.createdAt,
|
|
this.updatedAt,
|
|
this.mbti,
|
|
this.birthdate,
|
|
this.themeMode = 'system',
|
|
this.isBusinessMode = false,
|
|
this.defaultMarkup = 3.0,
|
|
this.hasCompletedOnboarding = false,
|
|
this.nickname,
|
|
this.gender,
|
|
this.totalExp = 0,
|
|
this.unlockedBadges = const [],
|
|
});
|
|
|
|
UserProfile copyWith({
|
|
String? fontPreference,
|
|
String? displayMode,
|
|
DateTime? createdAt,
|
|
DateTime? updatedAt,
|
|
String? mbti,
|
|
DateTime? birthdate,
|
|
String? themeMode,
|
|
bool? isBusinessMode,
|
|
double? defaultMarkup,
|
|
bool? hasCompletedOnboarding,
|
|
String? nickname,
|
|
String? gender,
|
|
int? totalExp,
|
|
List<String>? unlockedBadges,
|
|
}) {
|
|
return UserProfile(
|
|
fontPreference: fontPreference ?? this.fontPreference,
|
|
displayMode: displayMode ?? this.displayMode,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
mbti: mbti ?? this.mbti,
|
|
birthdate: birthdate ?? this.birthdate,
|
|
themeMode: themeMode ?? this.themeMode,
|
|
isBusinessMode: isBusinessMode ?? this.isBusinessMode,
|
|
defaultMarkup: defaultMarkup ?? this.defaultMarkup,
|
|
hasCompletedOnboarding: hasCompletedOnboarding ?? this.hasCompletedOnboarding,
|
|
nickname: nickname ?? this.nickname,
|
|
gender: gender ?? this.gender,
|
|
totalExp: totalExp ?? this.totalExp,
|
|
unlockedBadges: unlockedBadges ?? this.unlockedBadges,
|
|
);
|
|
}
|
|
}
|