check null safety

This commit is contained in:
tzw
2021-09-10 14:27:38 +06:30
parent a144c945b6
commit 7670779b03
57 changed files with 620 additions and 626 deletions

View File

@@ -7,17 +7,17 @@ class SharedPref {
static final SharedPref instance = SharedPref._();
SharedPref._();
static Future<bool> isFirstLaunch() async {
static Future<bool?> isFirstLaunch() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool('first_launch');
}
static Future<void> finishFirstLaunch() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setBool('first_launch', false);
prefs.setBool('first_launch', false);
}
static Future<String> getLang() async {
static Future<String?> getLang() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString('language');
}
@@ -27,7 +27,7 @@ class SharedPref {
prefs.setString('language', lang);
}
static Future<bool> getStaffMode() async {
static Future<bool?> getStaffMode() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool('staff_mode_on');
}
@@ -41,7 +41,7 @@ class SharedPref {
await _save("user", user.toJson());
}
static Future<User> getUser() async {
static Future<User?> getUser() async {
try {
return User.fromJson(await _read("user"));
} catch (e) {
@@ -57,7 +57,7 @@ class SharedPref {
await _save("skipped_recovery_email", skipped);
}
static Future<bool> getSkippedRecoverEmail() async {
static Future<bool?> getSkippedRecoverEmail() async {
try {
bool _skipped = await _read("skipped_recovery_email");
return _skipped;
@@ -69,7 +69,7 @@ class SharedPref {
static _read(String key) async {
try {
final prefs = await SharedPreferences.getInstance();
return json.decode(prefs.getString(key));
return json.decode(prefs.getString(key) ?? "");
} catch (e) {
print("Error:$e");
}