xray_network_dio_interceptor
Dio HTTP interceptor for xray_inspector.
Dio interceptor that captures all HTTP requests, responses, and errors into an XRayNetworkInspector.
Installation
dependencies:
xray_inspector: ^0.0.1
xray_network_dio_interceptor: ^0.0.1
dio: ^5.0.0
For setup, see Network Inspection.
How it works
XRayNetworkDioInterceptor hooks into Dio's interceptor lifecycle:
onRequest— Creates a newXRayNetworkCallwith statusloadingand stores the call ID in Dio's request optionsextramap.onResponse— Finds the call by ID and updates it with the response status code, headers, and body. Status becomessuccess.onError— Finds the call by ID and updates it with the error details. Status becomeserror.
Lifecycle states
| State | When |
|---|---|
loading | Request sent, waiting for response |
success | Response received with any status code |
error | Network error or Dio error |
Combining with other Dio interceptors
Add XRayNetworkDioInterceptor alongside other interceptors. Order matters — place it where you want the captured request/response to reflect the transformation state:
final dio = Dio()
..interceptors.addAll([
AuthInterceptor(), // runs first
XRayNetworkDioInterceptor(inspector: inspector), // captures after auth headers added
LogInterceptor(),
]);

