setupDio static method
Sets up and returns a Dio client configured with the given baseUrl
.
The Dio instance is configured with:
- JSON content type
- Connection timeout of 5 seconds
- Receive timeout of 5 seconds
- Retry interceptor with up to 3 retries and retry delays of 3, 5, and 5 seconds.
baseUrl
— The base URL for the Dio client.
Implementation
static Dio setupDio(String baseUrl) {
final dio = Dio(
BaseOptions(
contentType: 'application/json',
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 5),
baseUrl: baseUrl,
),
);
dio.interceptors.add(
RetryInterceptor(
dio: dio,
retries: 3,
retryDelays: const [
Duration(seconds: 3),
Duration(seconds: 5),
Duration(seconds: 5),
],
),
);
return dio;
}