SpUtils class

sp存储工具类,适合存储轻量级数据,不建议存储json长字符串

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

clear() Future<bool>?
clear. 清除sp
forEach() → void
遍历打印sp的key和value
getBool(String key, {bool defValue = false}) bool
get bool. 获取sp中key的布尔值
getDouble(String key, {double defValue = 0.0}) double
get double. 获取sp中key的double值
getDynamic(String key, {Object? defValue}) → dynamic
get dynamic. 获取sp中key的dynamic值
getInt(String key, {int defValue = 0}) int
get int. 获取sp中key的int值
getKeys() Set<String>?
get keys. 获取sp中所有的key
getObject(String key) Map?
获取sp中key的map数据
getObjectList(String key) List<Map>?
get object list. 获取sp中key的list集合
getString(String key, {String defValue = ''}) String
get string. 获取sp中key的字符串
getStringList(String key, {List<String> defValue = const []}) List<String>
get string list. 获取sp中key的list
getStringMap(String key) Map?
获取sp中key的map值
hasKey(String key) bool
判断是否存在key的数据
init() Future<SharedPreferences?>
初始化,必须要初始化
isInitialized() bool
检查初始化
putBool(String key, bool value) Future<bool>?
put bool. 存储sp中key的布尔值
putDouble(String key, double value) Future<bool>?
put double. 存储sp中key的double值
putInt(String key, int value) Future<bool>?
put int. 存储sp中key的int值
putObject(String key, Object? value) Future<bool>?
put object. 存储object类型数据
putObjectList(String key, List<Object> list) Future<bool>?
put object list. 存储sp中key的list集合
putString(String key, String value) Future<bool>?
put string. 存储sp中key的字符串
putStringList(String key, List<String> value) Future<bool>?
put string list. 存储sp中key的list
putStringList2(String key, List value) Future<bool>?
存储sp中key的list值
putStringMap(String key, Map value) Future<bool>?
存储sp中key的map值
remove(String key) Future<bool>?
remove. 移除sp中key的值