123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import 'package:shared_preferences/shared_preferences.dart';
- class SpUtil {
- static Future<SharedPreferences> _getInstance() {
- return SharedPreferences.getInstance();
- }
- static Future<bool> contains(String key) async {
- SharedPreferences sp = await _getInstance();
- return sp.containsKey(key);
- }
- static Future<bool> remove(String key) async {
- SharedPreferences sp = await _getInstance();
- return sp.remove(key);
- }
- static Future<bool> setInt(String key, int value) async {
- SharedPreferences sp = await _getInstance();
- return sp.setInt(key, value);
- }
- static Future<bool> setDouble(String key, double value) async {
- SharedPreferences sp = await _getInstance();
- return sp.setDouble(key, value);
- }
- static Future<bool> setBool(String key, bool value) async {
- SharedPreferences sp = await _getInstance();
- return sp.setBool(key, value);
- }
- static Future<bool> setString(String key, String value) async {
- SharedPreferences sp = await _getInstance();
- return sp.setString(key, value);
- }
- static Future<bool> setStringList(String key, List<String> value) async {
- SharedPreferences sp = await _getInstance();
- return sp.setStringList(key, value);
- }
- static Future<int> getInt(String key, {int defValue = 0}) async {
- SharedPreferences sp = await _getInstance();
- return sp.getInt(key) ?? defValue;
- }
- static Future<double> getDouble(String key, {double defValue = 0.0}) async {
- SharedPreferences sp = await _getInstance();
- return sp.getDouble(key) ?? defValue;
- }
- static Future<bool> getBool(String key, {bool defValue = false}) async {
- SharedPreferences sp = await _getInstance();
- return sp.getBool(key) ?? defValue;
- }
- static Future<String> getString(String key, {String defValue = ""}) async {
- SharedPreferences sp = await _getInstance();
- return sp.getString(key) ?? defValue;
- }
- static Future<List<String>> getStringList(String key) async {
- SharedPreferences sp = await _getInstance();
- return sp.getStringList(key) ?? [];
- }
- static Future<bool> getEnableDelayShot() {
- return getBool("delayShot", defValue: false);
- }
- static Future<bool> setEnabelDelayShot(bool bo) {
- return setBool("delayShot", bo);
- }
- static Future<int> getDelayShotTime() {
- return getInt("delayShotTime", defValue: 2);
- }
- static Future<bool> setDelayShotTime(int value) {
- return setInt("delayShotTime", value);
- }
- static Future<String> getUserId() {
- return getString("userId", defValue: "");
- }
- static Future<bool> setUserId(String userName) {
- return setString("userId", userName);
- }
- static Future<String> getUserName() {
- return getString("userName", defValue: "");
- }
- static Future<bool> setUserName(String userName) {
- return setString("userName", userName);
- }
- static Future<String> getToken() {
- return getString("token", defValue: "");
- }
- static Future<bool> setToken(String token) {
- return setString("token", token);
- }
- static Future<int> getSelectedPatientId() {
- return getInt("selectedPatientId", defValue: -1);
- }
- static Future<bool> setSelectedPatientId(int id) {
- return setInt("selectedPatientId", id);
- }
- static Future<bool> isAppStartAgreementAgreed() {
- return getBool("appStartAgreementAgreed", defValue: false);
- }
- static Future<bool> setAppStartAgreementAgreed(bool bo) {
- return setBool("appStartAgreementAgreed", bo);
- }
- static Future<bool> hasStoragePermissionRequested() {
- return getBool("storagePermissionRequested", defValue: false);
- }
- static Future<bool> setStoragePermissionRequested(bool bo) {
- return setBool("storagePermissionRequested", bo);
- }
- static Future<bool> hasLocationPermissionRequested() {
- return getBool("locationPermissionRequested", defValue: false);
- }
- static Future<bool> setLocationPermissionRequested(bool bo) {
- return setBool("locationPermissionRequested", bo);
- }
- }
|