BaiomySharedPrefs class
A singleton wrapper around SharedPreferences that provides typed
get / set / update / remove / clear operations with built-in error handling.
Supported types: String, int, double, bool, List<String>,
and any JSON-serialisable object via setObject / getObject.
Usage:
await BaiomySharedPrefs.instance.init();
await BaiomySharedPrefs.instance.setString('username', 'Ahmad');
final name = await BaiomySharedPrefs.instance.getString('username');
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< void> - Removes all values from SharedPreferences.
-
containsKey(
String key) → bool -
Returns
trueifkeyexists in the store. -
get(
String key) → dynamic -
Returns the raw dynamic value for
key, ornullif not found. -
getBool(
String key, {bool? defaultValue}) → bool? -
Returns the stored bool, or
defaultValueif not found. -
getDouble(
String key, {double? defaultValue}) → double? -
Returns the stored double, or
defaultValueif not found. -
getInt(
String key, {int? defaultValue}) → int? -
Returns the stored int, or
defaultValueif not found. -
getKeys(
) → Set< String> - Returns all stored keys.
-
getObject(
String key) → Map< String, dynamic> ? -
Retrieves and decodes a JSON object stored under
key. -
getString(
String key, {String? defaultValue}) → String? -
Returns the stored String, or
defaultValueif not found. -
getStringList(
String key, {List< String> ? defaultValue}) → List<String> ? -
Returns the stored
List<String>, ordefaultValueif not found. -
init(
) → Future< void> - Must be called once before using any other method.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patchObject(
String key, Map< String, dynamic> patch) → Future<void> -
Updates an existing JSON object by merging
patchinto the stored value. -
remove(
String key) → Future< void> -
Removes the value stored under
key. -
setBool(
String key, {required bool value}) → Future< void> - Saves or overwrites a bool value.
-
setDouble(
String key, double value) → Future< void> - Saves or overwrites a double value.
-
setInt(
String key, int value) → Future< void> - Saves or overwrites an int value.
-
setObject(
String key, Map< String, dynamic> value) → Future<void> -
Serialises
valueto JSON and saves it underkey. -
setString(
String key, String value) → Future< void> - Saves or overwrites a String value.
-
setStringList(
String key, List< String> value) → Future<void> -
Saves or overwrites a
List<String>value. -
toString(
) → String -
A string representation of this object.
inherited
-
updateBool(
String key, {required bool newValue}) → Future< void> - Updates an existing key with a new bool value.
-
updateDouble(
String key, double newValue) → Future< void> - Updates an existing key with a new double value.
-
updateInt(
String key, int newValue) → Future< void> - Updates an existing key with a new int value.
-
updateString(
String key, String newValue) → Future< void> - Updates an existing key with a new String value.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → BaiomySharedPrefs
-
The single instance of BaiomySharedPrefs.
final