SpUtil class
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
-
clear()
→ Future<bool>
-
清空所有数据
-
containsKey(String key)
→ bool
-
是否包含指定键
-
ensureInitialized()
→ Future<void>
-
-
getBool(String key, {bool defValue = false})
→ bool?
-
获取布尔值
-
getDouble(String key, {double defValue = 0.0})
→ double?
-
获取浮点数
-
getInt(String key, {int defValue = 0})
→ int?
-
获取整数
-
getKeys()
→ Set<String>?
-
获取所有键
-
getObject<T>(String key, T fromJson(Map<String, dynamic> json), {T? defValue})
→ T?
-
获取对象
-
getObjectList<T>(String key, T fromJson(Map<String, dynamic> json), {List<T>? defValue = const []})
→ List<T>?
-
获取对象列表
-
getSp()
→ SharedPreferences?
-
获取原始 SharedPreferences 实例
-
getString(String key, {String? defValue = ''})
→ String?
-
获取字符串
-
getStringList(String key, {List<String>? defValue = const []})
→ List<String>?
-
获取字符串列表
-
init()
→ Future<SharedPreferences?>
-
-
isInitialized()
→ bool
-
检查是否已初始化
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
putBool(String key, bool value)
→ Future<bool>
-
存储布尔值
-
putDouble(String key, double value)
→ Future<bool>
-
存储浮点数
-
putInt(String key, int value)
→ Future<bool>
-
存储整数
-
putObject(String key, Object value)
→ Future<bool>
-
存储对象
class User {
-
putObjectList(String key, List<Object> list)
→ Future<bool>
-
存储对象列表
-
putString(String key, String value)
→ Future<bool>
-
存储字符串
-
putStringList(String key, List<String> value)
→ Future<bool>
-
存储字符串列表
-
reload()
→ Future<void>
-
重新加载数据(用于调试或热更新)
-
remove(String key)
→ Future<bool>
-
移除某个键
-
toString()
→ String
-
A string representation of this object.
inherited