add structure

This commit is contained in:
2020-05-29 07:45:27 +06:30
parent 4c851d9971
commit bad27ba5c4
272 changed files with 36065 additions and 174 deletions

View File

@@ -0,0 +1,76 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fcs/vo/report.dart';
import 'dart:convert';
import 'package:fcs/vo/user.dart';
class SharedPref {
static final SharedPref instance = SharedPref._();
SharedPref._();
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<void> saveReport(ReportFieldPositionSelection report) async {
await _save('report-${report.id}', report.toJson());
}
static Future<ReportFieldPositionSelection> getReport(String id) async {
try {
return ReportFieldPositionSelection.fromJson(await _read("report-$id"));
} catch (e) {
return null;
}
}
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 {
final prefs = await SharedPreferences.getInstance();
return json.decode(prefs.getString(key));
}
static _save(String key, value) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString(key, json.encode(value));
}
static _remove(String key) async {
final prefs = await SharedPreferences.getInstance();
prefs.remove(key);
}
}