local_storage.dart
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/config/app_environment.dart';
import '../../core/constants/storage_const.dart';
/// Opens local persistence accessors used during bootstrap.
class LocalStorage {
LocalStorage._(this.sharedPreferences);
final SharedPreferences sharedPreferences;
static Future<LocalStorage> open() async {
final prefs = await SharedPreferences.getInstance();
return LocalStorage._(prefs);
}
// ─── Environment Configuration Storage ──────────────────────────────────────
Future<AppEnvironment> readEnvironment() async {
final ordinal = sharedPreferences.getInt(StorageConst.appEnvironmentKey);
if (ordinal == null) {
return AppEnvironment.release;
}
return AppEnvironment.fromOrdinal(ordinal);
}
Future<void> writeEnvironment(AppEnvironment environment) async {
await sharedPreferences.setInt(
StorageConst.appEnvironmentKey,
environment.index,
);
}
// ─── App Settings Storage ──────────────────────────────────────────────────
bool get termsAgreed =>
sharedPreferences.getBool(StorageConst.termsAgreedKey) ?? false;
Future<void> setTermsAgreed(bool value) async {
await sharedPreferences.setBool(StorageConst.termsAgreedKey, value);
}
String get lastLoginMethod =>
sharedPreferences.getString(StorageConst.lastLoginMethodKey) ?? '';
Future<void> setLastLoginMethod(String value) async {
await sharedPreferences.setString(StorageConst.lastLoginMethodKey, value);
}
// ─── App Review Prompt Storage ──────────────────────────────────────────────
DateTime? get appReviewPromptNextShowAt {
final value = sharedPreferences.getInt(
StorageConst.appReviewPromptNextShowAtKey,
);
if (value == null || value <= 0) return null;
return DateTime.fromMillisecondsSinceEpoch(value);
}
Future<void> setAppReviewPromptNextShowAt(DateTime value) async {
await sharedPreferences.setInt(
StorageConst.appReviewPromptNextShowAtKey,
value.millisecondsSinceEpoch,
);
}
}