DfHttpClientConfig constructor
DfHttpClientConfig({
- required String baseApiUrl,
- Encoding? encoding,
- Map<
String, String> headers = const {}, - int timeout = 10,
- bool retryApiCall = true,
- bool waitForTokenRefresh = true,
- int maxRetryAttempts = 3,
- Future<
Result< refreshToken()?,String, Exception> > - int maxDelayMs = 60000,
- Random? random,
- Future<
bool> internetConnectionCheck()?,
Creates a new DfHttpClientConfig instance.
baseApiUrl is required and should be the base URL for your API.
encoding: Optional request/response encoding (e.g. UTF-8).headers: Default headers added to every request.timeout: Request timeout in seconds (default: 10).retryApiCall: Whether failed API calls should automatically retry.waitForTokenRefresh: Whether requests should wait until token refresh completes.maxRetryAttempts: Maximum number of retry attempts for failed requests.refreshToken: Callback used to refresh tokens if authentication fails.maxDelayMs: Represent the maximum waiting time on API retry. Default set to 60000msinternetConnectionCheckCheck if the device is really connected to the internet by default it check if the 'example.com' is available, the custom logic can be implemented
random: Provide a "seeded" Random in tests so that the retry delay is predictable
Implementation
DfHttpClientConfig({
required this.baseApiUrl,
this.encoding,
this.headers = const {},
this.timeout = 10,
this.retryApiCall = true,
this.waitForTokenRefresh = true,
this.maxRetryAttempts = 3,
this.refreshToken,
this.maxDelayMs = 60000,
Random? random,
Future<bool> Function()? internetConnectionCheck,
})
: _rand = random ?? Random(),
hasInternetConnection = internetConnectionCheck??_hasInternetConnection;