ApiService<User, UserModel> class
abstract
An abstract class representing an API service in a Flutter application.
This class provides a base implementation for services that interact with APIs
while handling authentication state changes and token updates. It leverages a provided
AuthenticationService
instance to retrieve user information and tokens.
Subclasses must implement the getUser
method to handle user data retrieval
specific to their API.
Constructors
- ApiService({required BuildContext context})
- Creates a new ApiService instance with the provided BuildContext.
Properties
-
authState
→ Stream<
UserModel?> -
A stream that emits UserModel updates whenever the authentication state changes.
no setter
- context → BuildContext
-
The BuildContext of the widget the service is associated with.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- user → UserModel?
-
The currently cached UserModel representing the authenticated user, or null if not authenticated.
no setter
Methods
-
dispose(
) → void - Disposes the subscriptions to avoid memory leaks.
-
getUser(
) → Future< UserModel> - Fetches and returns the UserModel representing the currently authenticated user.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setToken(
String? token) → void - Sets the authentication token for the API service.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited