configureNetworkService static method
Future<void>
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()?,
Initialises the network service. Must be called before any HTTP request.
Parameters:
baseURL: Base URL prepended to every endpoint.connectTimeout: Max time to open a connection (default 15 s).receiveTimeout: Max time to receive a response (default 25 s).contentType: DefaultContent-Type(defaultapplication/json).headers: Additional default headers for every request.pemCertificate: PEM-encoded certificate string for SSL pinning.localCertificateBytes: Raw certificate bytes for SSL pinning.isDevEnv: Disables TLS certificate validation in development only.cacheEncryptionKey: Required 32-byte key for AES-256 cache encryption.cacheVersion: Hive box version (default1). Increment this whenever the cache schema changes — the old box is abandoned and a fresh one is created automatically. No manual migration code required.onUnauthorized: Global callback fired on every 401/403 response. Individual requests can override this with their ownunAuthorizedCallBack.
Implementation
static Future<void> 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 Function()? onUnauthorized,
}) async {
_globalUnauthorizedCallback = onUnauthorized;
await NetworkCacheService().initCacheService(
encryptionKey: cacheEncryptionKey,
cacheVersion: cacheVersion,
);
_apiManager = ApiManagerImpl();
_apiRequest = ApiRequestImpl();
_apiManager.initialize(
baseURL: baseURL,
headers: headers,
connectTimeout: connectTimeout,
contentType: contentType,
isToEnableSSLCertificate:
!isDevEnv && (pemCertificate != null || localCertificateBytes != null),
localCertificateBytes: localCertificateBytes,
pemCertificate: pemCertificate,
receiveTimeout: receiveTimeout,
isDevEnv: isDevEnv,
);
}