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:

  1. onRequest — Creates a new XRayNetworkCall with status loading and stores the call ID in Dio's request options extra map.
  2. onResponse — Finds the call by ID and updates it with the response status code, headers, and body. Status becomes success.
  3. onError — Finds the call by ID and updates it with the error details. Status becomes error.

Lifecycle states

StateWhen
loadingRequest sent, waiting for response
successResponse received with any status code
errorNetwork 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(),
  ]);