NetworkService class

Entry point for all network operations.

Call configureNetworkService once at app startup (before any HTTP call), then access requests via NetworkService.apiRequest.

await NetworkService.configureNetworkService(
  baseURL: 'https://api.example.com',
  cacheEncryptionKey: 'your-32-character-secret-key-here',
  onUnauthorized: () => AppRouter.goToLogin(),
);

Constructors

NetworkService()
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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

apiManager ApiManager
Direct access to the underlying ApiManager (Dio instance).
no setter
apiRequest ApiRequest
Access point for all HTTP request operations.
no setter
globalUnauthorizedCallback → void Function()?
The app-wide 401/403 callback registered at startup.
no setter

Static Methods

clearAuthToken() → void
Removes the Authorization header from all subsequent requests.
clearCache() Future<void>
Clears all cached responses from the active Hive box.
configureNetworkService({String baseURL = '', Duration connectTimeout = const Duration(seconds: 15), Duration receiveTimeout = const Duration(seconds: 25), String contentType = Headers.jsonContentType, Map<String, dynamic> headers = const {'Accept' : 'application/json'}, String? pemCertificate, Uint8List? localCertificateBytes, bool isDevEnv = false, required String cacheEncryptionKey, int cacheVersion = 1, void onUnauthorized()?}) Future<void>
Initialises the network service. Must be called before any HTTP request.
setAuthToken(String token) → void
Sets the Authorization: Bearer <token> header on all subsequent requests.
updateHeaders(Map<String, dynamic> headers) → void
Merges headers into the default headers sent on every request.
warmCache(List<WarmCacheRequest> requests) Future<void>
Pre-populates the cache by firing all requests concurrently.