SpUtil class

shared_preferences缓存插件方法封装

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>?
清空所有缓存
getData<T>(String key, {T? defValue}) → T
获取缓存数据,只能获取常规类型,如需要获取复杂类型,使用自定义获取缓存结构类型的方法。
getDynamic(String key, {Object? defValue}) → dynamic
获取缓存数据,返回dynamic类型
getInstance() Future<SpUtil>
初始化SharedPreferences缓存对象
getKeys() Set<String>
获取所有Key
getList<T>(String key, {List<T>? defValue}) Future<List<T>>
获取普通的List
getListCustom<T>(String key, T f(T v), {List<T>? defValue}) Future<List<T>>
获取自定义的List类型的数据 第二参数Fn自定义转换结果,并返回类型
getMap<T>(String key, {T? defValue}) Future<T>
获取Map类型缓存,内部类型未定义
getMapCustom<T>(String key, T f(Object v)) Future<T>
获取自定义的Map类型数据 第二参数Fn自定义转换结果,,并返回类型
hasKey(String key) bool
查找是否有指定key
reload() Future<void>
重新加载缓存数据
remove(String key) Future<bool>?
移除指定key缓存
setData<T>(String key, T value) Future<bool>
设置变量到缓存中去,返回设置缓存结果,true成功,false失败。 支持String、int、double、bool类型,
setListData<T>(String key, List<T> value, {bool cast = false}) Future<bool>
设置list类型到缓存中去
setMapData<T>(String key, T value, {bool cast = false}) Future<bool>
设置Map类型到缓存中去, cast 是否强制转换,强制转换成字符串有可能会转换的不完整