feat(首页欢迎图, 加入第一次访问判断.):

This commit is contained in:
sanfan.hx
2019-02-01 17:25:47 +08:00
parent b78c94d213
commit a46fcc3cf4
5 changed files with 66 additions and 43 deletions

View File

@ -1,13 +1,13 @@
import 'dart:async';
import 'package:shared_preferences/shared_preferences.dart';
export 'package:flutter_go/resources/shared_preferences_keys.dart';
///
/// 用来做shared_preferences的存储
class SpUtil {
static SpUtil _instance;
static Future<SpUtil> get instance async {
return await _getInstance();
return await getInstance();
}
static SharedPreferences _spf;
@ -19,7 +19,8 @@ class SpUtil {
_spf = await SharedPreferences.getInstance();
}
static Future<SpUtil> _getInstance() async {
static Future<SpUtil> getInstance() async {
print("_instance>>$_instance");
if (_instance == null) {
_instance = new SpUtil._();
await _instance._init();
@ -29,83 +30,90 @@ class SpUtil {
}
static bool _beforCheck() {
String a;
if (_spf == null) {
return throw new StateError("SharedPreferences must be initialized first, but the insurance is null;");
return true;
}
return false;
}
// 判断是否存在数据
bool hasKey(String key) {
Set keys = getKeys();
return keys.contains(key);
}
static Set<String> getKeys() {
Set<String> getKeys() {
if (_beforCheck()) return null;
return _spf.getKeys();
}
dynamic get(String key) {
get(String key) {
if (_beforCheck()) return null;
return _spf.getKeys();
return _spf.get(key);
}
static String getString(String key) {
getString(String key) {
if (_beforCheck()) return null;
return _spf.getString(key);
}
static Future<bool> putString(String key, String value) {
Future<bool> putString(String key, String value) {
if (_beforCheck()) return null;
return _spf.setString(key, value);
}
static bool getBool(String key) {
bool getBool(String key) {
if (_beforCheck()) return null;
return _spf.getBool(key);
}
static Future<bool> putBool(String key, bool value) {
Future<bool> putBool(String key, bool value) {
if (_beforCheck()) return null;
return _spf.setBool(key, value);
}
static int getInt(String key) {
int getInt(String key) {
if (_beforCheck()) return null;
return _spf.getInt(key);
}
static Future<bool> putInt(String key, int value) {
Future<bool> putInt(String key, int value) {
if (_beforCheck()) return null;
return _spf.setInt(key, value);
}
static double getDouble(String key) {
double getDouble(String key) {
if (_beforCheck()) return null;
return _spf.getDouble(key);
}
static Future<bool> putDouble(String key, double value) {
Future<bool> putDouble(String key, double value) {
if (_beforCheck()) return null;
return _spf.setDouble(key, value);
}
static List<String> getStringList(String key) {
List<String> getStringList(String key) {
return _spf.getStringList(key);
}
static Future<bool> putStringList(String key, List<String> value) {
Future<bool> putStringList(String key, List<String> value) {
if (_beforCheck()) return null;
return _spf.setStringList(key, value);
}
static dynamic getDynamic(String key) {
dynamic getDynamic(String key) {
if (_beforCheck()) return null;
return _spf.get(key);
}
static Future<bool> remove(String key) {
Future<bool> remove(String key) {
if (_beforCheck()) return null;
return _spf.remove(key);
}
static Future<bool> clear() {
Future<bool> clear() {
if (_beforCheck()) return null;
return _spf.clear();
}
}
}