PreferenceHelper class

A helper class for managing user preferences and persistent storage.

The PreferenceHelper class provides methods to initialize, save, retrieve, and remove user-related data and settings using SharedPreferences.

Constructors

PreferenceHelper.new()
Factory constructor to return the singleton instance.
factory

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

getAutoLogin() bool
Gets the auto-login preference, returns false if not set.
getBool(String key) bool?
Gets a boolean value for the given key, returns null if not found.
getInt(String key) int?
Gets an integer value for the given key, returns null if not found.
getString(String key) String?
Gets a string value for the given key, returns null if not found.
getUser() UserModel?
Retrieves the user data from preferences, returns null if not found.
getUserRole() String
Gets the user role, returns UserRoles.admin if user not found.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeUser() → void
Removes the stored user data.
saveUser(UserModel user) Future<void>
Saves the user data as a JSON string in preferences.
setAutoLogin(bool isAutoLogin) → void
Sets the auto-login preference.
setBool(String key, bool value) → void
Sets a boolean value for the given key.
setInt(String key, int value) → void
Sets an integer value for the given key.
setString(String key, String value) → void
Sets a string value for the given key.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

init() Future<void>
Initializes the SharedPreferences instance.

Constants

autoLogin → const String
Key for auto-login preference.
users → const String
Key for storing user data.