SharedPreferencesPlus class
Dart wrapper around the platform implementation of shared preferences.
Reads are synchronous and require the in-memory cache to be initialized via
getInstance before any get* calls are made. Writes are asynchronous and
update the cache after the platform write completes.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- options → SharedPreferencesPlusOptions
-
Options that control the underlying preferences namespace.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → Future< void> - Clears all stored preferences for this options namespace.
-
containsKey(
String key) → bool -
Returns
trueifkeyexists. -
getAll(
) → Map< String, Object> - Returns all stored preferences for this options namespace.
-
getBool(
String key) → bool? -
Returns the boolean stored for
key, ornullif not present. -
getDouble(
String key) → double? -
Returns the double stored for
key, ornullif not present. -
getInt(
String key) → int? -
Returns the integer stored for
key, ornullif not present. -
getKeys(
) → Set< String> - Returns the set of all keys stored in this preferences namespace.
-
getString(
String key) → String? -
Returns the string stored for
key, ornullif not present. -
getStringList(
String key) → List< String> ? -
Returns the string list stored for
key, ornullif not present. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reload(
) → Future< void> - Reloads preferences for this options namespace into the shared cache.
-
remove(
String key) → Future< void> -
Removes the value stored for
key, if any. -
setBool(
String key, bool value) → Future< void> -
Stores a boolean value under
key. -
setDouble(
String key, double value) → Future< void> -
Stores a double value under
key. -
setInt(
String key, int value) → Future< void> -
Stores an integer value under
key. -
setString(
String key, String value) → Future< void> -
Stores a string value under
key. -
setStringList(
String key, List< String> value) → Future<void> -
Stores a list of strings under
key. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
clearCache(
{SharedPreferencesPlusOptions options = const SharedPreferencesPlusOptions()}) → void -
Clears the shared cache for the provided
options. -
getInstance(
{SharedPreferencesPlusOptions options = const SharedPreferencesPlusOptions()}) → Future< SharedPreferencesPlus> -
Loads preferences for
optionsinto the shared cache and returns an instance. -
setMockInitialValues(
Map< String, Object?> values, {SharedPreferencesPlusOptions options = const SharedPreferencesPlusOptions()}) → void -
Sets initial values for tests and initializes the cache for
options.