dio property
Dio
get
dio
The lazily-initialised Dio instance shared by all requests.
Built once using resolveBaseUrl and defaultHeaders. Dio is
configured with validateStatus: (_) => true so that all HTTP
responses—including 4xx and 5xx—are returned to Lucky rather than
converted into a DioException. Error handling is performed by
send after receiving the response.
Implementation
Dio get dio {
if (_dio != null) return _dio!;
_dio = Dio(BaseOptions(
baseUrl: resolveBaseUrl(),
headers: defaultHeaders(),
// Lucky handles HTTP errors itself via throwOnError.
// All responses are allowed through so that Dio never throws a
// DioException.badResponse before Lucky has a chance to act.
validateStatus: (_) => true,
));
// Add the logging interceptor only when both the flag and callback are set.
if (enableLogging && onLog != null) {
_dio!.interceptors.add(LoggingInterceptor(onLog: onLog!));
}
// Add the debug interceptor only when both the flag and callback are set.
if (debugMode && onDebug != null) {
_dio!.interceptors.add(DebugInterceptor(onDebug: onDebug!));
}
// Append any user-provided custom interceptors.
_dio!.interceptors.addAll(interceptors);
return _dio!;
}