ApiClient constructor
ApiClient({
- bool shouldUsePersistentUrl = false,
- bool shouldUseDeviceInfo = false,
- bool shouldUseLanguage = true,
- RefreshInterceptor? refreshInterceptor,
Creates an ApiClient instance with configurable interceptors.
Parameters:
shouldUsePersistentUrl: Enable dynamic base URL switching (default: false)shouldUseDeviceInfo: Include device information headers (default: false)shouldUseLanguage: Include user language headers (default: true)refreshInterceptor: Custom token refresh interceptor (optional)
Interceptors Added (in order):
- DeviceInfoInterceptor (if enabled)
- LanguageInterceptor (if enabled)
- Cookie storage interceptor (native platforms only)
- Persistent URL interceptor (if enabled, native platforms only)
- TimezoneInterceptor (always added)
- GeneralErrorLogInterceptor (always added)
- RefreshInterceptor (always added)
Implementation
ApiClient({
bool shouldUsePersistentUrl = false,
bool shouldUseDeviceInfo = false,
bool shouldUseLanguage = true,
RefreshInterceptor? refreshInterceptor,
}) : dio = Dio() {
if (refreshInterceptor != null) {
this.refreshInterceptor = refreshInterceptor;
}
dio.options.baseUrl = baseUrl;
if (shouldUseDeviceInfo) {
dio.interceptors.add(DeviceInfoInterceptor());
}
if (shouldUseLanguage) {
dio.interceptors.add(LanguageInterceptor());
}
dio.addCookieStorageInterceptor();
if (shouldUsePersistentUrl) {
dio.addBaseUrlInterceptor();
}
dio.interceptors
..add(TimezoneInterceptor())
..add(GeneralErrorLogInterceptor())
..add(this.refreshInterceptor);
}