AuthProvider class

A provider class that manages user authentication state and interactions.

This class handles user login, logout, password setting, and manages user and hospital data, including FCM tokens and current block/ward information. It uses shared_preferences for persistent storage of authentication data.

Mixed-in types

Constructors

AuthProvider.new()

Properties

error String?
Returns the current error message, or null if no error.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
hospital Hospital?
Returns the hospital associated with the authenticated user.
no setter
isApprover bool
Returns true if the current user is an approver.
no setter
isAuthenticated bool
Returns true if a user is authenticated (user and token are present), false otherwise.
no setter
isCreator bool
Returns true if the current user is a creator.
no setter
isLoading bool
Returns true if an asynchronous operation is in progress, false otherwise.
no setter
isResponder bool
Returns true if the current user is a responder.
no setter
isStaff bool
Returns true if the current user is staff (currently same as superuser).
no setter
isSuperuser bool
Returns true if the current user is a superuser.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token String?
Returns the authentication token.
no setter
user User?
Returns the currently authenticated user.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clearError() → void
Public method to clear any existing error message.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
fetchUserData() Future<bool>
Fetches the latest user data from the API.
initializeAuth() Future<void>
Initializes the authentication state from shared_preferences.
login(String phoneNumber, String password) Future<bool>
Attempts to log in a user with the given phoneNumber and password.
logout() Future<void>
Logs out the current user.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
refreshUser() Future<bool>
Refreshes the user's authentication token and data.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setPassword(String phoneNumber, String password) Future<bool>
Attempts to set or reset a user's password.
toString() String
A string representation of this object.
inherited
updateCurrentBlock(int blockId, String blockName) Future<bool>
Updates the user's currently selected block.
updateCurrentWard(int wardId, String wardName, {int? floor, String? blockName}) Future<void>
Updates the user's currently selected ward.
updateFCMToken(String fcmToken, {int? blockId}) Future<bool>
Updates the user's FCM (Firebase Cloud Messaging) token.
updateUserDirectly(User updatedUser) → void
Directly updates the internal user object and notifies listeners.

Operators

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