ApiClient class

Cliente HTTP centralizado de la aplicación, basado en Dio.

Configura automáticamente la baseUrl según la plataforma (emulador Android vs iOS/escritorio), timeouts de conexión y recepción, e interceptores para:

  • Inyección JWT: adjunta el token Authorization: Bearer en cada petición cuando getToken está disponible.
  • Expiración de sesión: detecta respuestas 401 durante el uso activo de la app (excluyendo el propio login) e invoca onUnauthorized.

Los métodos get, post, put y patch traducen cualquier DioException a una AuthException con mensajes legibles en español mediante _handleError.

Constructors

ApiClient({Future<String?> getToken()?, void onUnauthorized()?, Dio? dio})
onUnauthorized: callback que se invoca cuando la API devuelve 401 durante una sesión activa (token caducado en mitad del uso). Se usa desde main.dart para limpiar el estado y redirigir al Login. dio es opcional y se utiliza para inyectar mocks durante los tests.

Properties

getToken Future<String?> Function()?
Función asíncrona que devuelve el token JWT almacenado, o null si el usuario no ha iniciado sesión.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get(String path, {Map<String, dynamic>? queryParams}) Future<Response>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch(String path, {dynamic data}) Future<Response>
post(String path, {dynamic data}) Future<Response>
put(String path, {dynamic data}) Future<Response>
toString() String
A string representation of this object.
inherited

Operators

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