SharepUtil class

SharedPreferences 工具类

提供对 SharedPreferences 的常用操作方法,包括初始化、数据的存储与读取、移除、清空等。

应用启动时应先初始化:

await SharepUtil.init();

Constructors

SharepUtil()

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<void>
清空所有 SharedPreferences 存储数据
getBool(String key, {bool defaultValue = false}) bool
获取布尔值类型的数据
getDouble(String key, {double defaultValue = 0.0}) double
获取双精度浮点数
getInt(String key, {int defaultValue = 0}) int
获取整型数据
getString(String key, {String defaultValue = ''}) String
获取字符串类型的数据
getStringList(String key, {List<String> defaultValue = const []}) List<String>
获取字符串列表数据
init() Future<SharedPreferences>
初始化 SharedPreferences 实例
remove(String key) Future<void>
删除指定 key 的数据
setBool(String key, bool value) Future<void>
存储布尔值到 SharedPreferences
setDouble(String key, double value) Future<void>
存储双精度类型到 SharedPreferences
setInt(String key, int value) Future<void>
存储整型值到 SharedPreferences
setString(String key, String value) Future<void>
存储字符串到 SharedPreferences
setStringList(String key, List<String> value) Future<void>
存储字符串列表到 SharedPreferences