ApiConfig class

Global API Configuration Class This class manages all API settings including base URL, headers, timeouts, and more.

Constructors

ApiConfig()
Returns the singleton instance of ApiConfig.
factory

Properties

baseUrl → String
Base URL for all API calls.
no setter
checkInternetBeforeCall → bool
Whether to verify internet connectivity before making API calls.
no setter
connectTimeout → Duration
Connect timeout duration.
no setter
enableLogs → bool
Whether console logs are enabled.
no setter
enableRetry → bool
Whether automatic retries are enabled.
no setter
exponentialBackoff → bool
Whether exponential backoff is used for retry delays.
no setter
globalExceptionHandler → dynamic Function(dynamic exception)?
Global exception handler callback.
no setter
globalHeaders → Map<String, dynamic>
Global headers applied to all requests.
no setter
hashCode → int
The hash code for this object.
no setterinherited
onUnauthorized → dynamic Function()?
Callback for unauthorized responses (401).
no setter
receiveTimeout → Duration
Receive timeout duration.
no setter
retryCount → int
Maximum number of retry attempts.
no setter
retryDelay → Duration
Delay duration between retries.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sendTimeout → Duration
Send timeout duration.
no setter
token → String?
Authentication token used for Authorization headers.
no setter

Methods

addHeader(String key, dynamic value) → void
Add or update a global header
clearHeaders() → void
Clear all global headers
initialize({required String baseUrl, Map<String, dynamic>? headers, String? token, Duration? connectTimeout, Duration? receiveTimeout, Duration? sendTimeout, bool enableLogs = true, bool enableRetry = false, int retryCount = 3, Duration? retryDelay, bool exponentialBackoff = false, dynamic globalExceptionHandler(dynamic exception)?, dynamic onUnauthorized()?, bool checkInternetBeforeCall = true}) → void
Initialize configuration with required parameters
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeHeader(String key) → void
Remove a global header
reset() → void
Reset configuration to defaults
setGlobalExceptionHandler(dynamic handler(dynamic exception)?) → void
Set global exception handler
setLogging(bool enable) → void
Enable or disable logging
setUnauthorizedCallback(dynamic callback()?) → void
Set unauthorized callback
toString() → String
A string representation of this object.
inherited
updateBaseUrl(String newBaseUrl) → void
Update base URL dynamically
updateHeaders(Map<String, dynamic> headers) → void
Update global headers
updateRetryConfig({bool? enableRetry, int? retryCount, Duration? retryDelay, bool? exponentialBackoff}) → void
Update retry configuration
updateTimeouts({Duration? connectTimeout, Duration? receiveTimeout, Duration? sendTimeout}) → void
Update timeout settings
updateToken(String? newToken) → void
Update token dynamically (for authentication)

Operators

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