This commit is contained in:
Sai Naw Wun
2020-10-07 02:33:06 +06:30
parent 01a2798a74
commit 65dda16fe6
475 changed files with 1543 additions and 90780 deletions

View File

@@ -0,0 +1,81 @@
import 'dart:convert';
import 'package:fcs/domain/entities/user.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SharedPref {
static final SharedPref instance = SharedPref._();
SharedPref._();
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);
}
static Future<String> getLang() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString('language');
}
static Future<void> saveLang(String lang) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('language', lang);
}
static Future<void> saveUser(User user) async {
await _save("user", user.toJson());
}
static Future<User> getUser() async {
try {
return User.fromJson(await _read("user"));
} catch (e) {
return null;
}
}
static Future<User> removeUser() async {
return await _remove("user");
}
static Future<void> saveSkippedRecoverEmail(bool skipped) async {
await _save("skipped_recovery_email", skipped);
}
static Future<bool> getSkippedRecoverEmail() async {
try {
bool _skipped = await _read("skipped_recovery_email");
return _skipped;
} catch (e) {
return null;
}
}
static _read(String key) async {
try {
final prefs = await SharedPreferences.getInstance();
return json.decode(prefs.getString(key));
} catch (e) {
print("Error:$e");
}
}
static _save(String key, value) async {
try {
final prefs = await SharedPreferences.getInstance();
prefs.setString(key, json.encode(value));
} catch (e) {
print("Error:$e");
}
}
static _remove(String key) async {
final prefs = await SharedPreferences.getInstance();
prefs.remove(key);
}
}