This commit is contained in:
2026-08-08 10:57:54 +08:00
parent d0d48c1ffc
commit 604af909b0
184 changed files with 12521 additions and 12722 deletions
+76
View File
@@ -0,0 +1,76 @@
import 'package:isar/isar.dart';
import '../../../core/constants/app_defaults.dart';
part 'app_config.g.dart';
enum EntitlementSource {
none,
purchase,
restore,
}
@collection
class AppConfig {
AppConfig();
Id id = AppDefaults.singletonId;
@Index(unique: true, replace: true)
late String configKey;
@Index(type: IndexType.value)
late DateTime updatedAt;
late DateTime createdAt;
int freeTrialLimit = AppDefaults.defaultFreeTrialLimit;
int usedTrialCount = 0;
bool isVipUnlocked = false;
DateTime? vipUnlockedAt;
String? lastIapErrorMessage;
@enumerated
EntitlementSource entitlementSource = EntitlementSource.none;
factory AppConfig.createDefault({DateTime? now}) {
final current = now ?? DateTime.now();
return AppConfig()
..configKey = 'local_app_config'
..createdAt = current
..updatedAt = current
..freeTrialLimit = AppDefaults.defaultFreeTrialLimit
..usedTrialCount = 0
..isVipUnlocked = false
..entitlementSource = EntitlementSource.none;
}
int get remainingTrialCount {
final remaining = freeTrialLimit - usedTrialCount;
return remaining > 0 ? remaining : 0;
}
bool get canStartScoring => isVipUnlocked || usedTrialCount < freeTrialLimit;
AppConfig copyWith({
int? freeTrialLimit,
int? usedTrialCount,
bool? isVipUnlocked,
DateTime? vipUnlockedAt,
String? lastIapErrorMessage,
EntitlementSource? entitlementSource,
DateTime? updatedAt,
}) {
return AppConfig()
..id = id
..configKey = configKey
..createdAt = createdAt
..updatedAt = updatedAt ?? DateTime.now()
..freeTrialLimit = freeTrialLimit ?? this.freeTrialLimit
..usedTrialCount = usedTrialCount ?? this.usedTrialCount
..isVipUnlocked = isVipUnlocked ?? this.isVipUnlocked
..vipUnlockedAt = vipUnlockedAt ?? this.vipUnlockedAt
..lastIapErrorMessage = lastIapErrorMessage ?? this.lastIapErrorMessage
..entitlementSource = entitlementSource ?? this.entitlementSource;
}
}