Network Inspection

Capture and inspect HTTP network calls from Dio or Serverpod.

The network inspector captures every HTTP request, response, and error made through your HTTP client, storing them in memory for real-time inspection.

Packages

Use casePackage
Dioxray_network_dio_interceptor

Setup with Dio

import 'package:xray_inspector/xray_inspector.dart';
import 'package:xray_network_dio_interceptor/xray_network_dio_interceptor.dart';
import 'package:dio/dio.dart';

final networkInspector = XRayNetworkInspector();

final dio = Dio()
  ..interceptors.add(
    XRayNetworkDioInterceptor(inspector: networkInspector),
  );

Accessing captured calls

// All captured calls (snapshot)
final calls = networkInspector.calls;

// Reactive — rebuilds your widget when calls change
ValueListenableBuilder<List<XRayNetworkCall>>(
  valueListenable: networkInspector.callsNotifier,
  builder: (context, calls, _) {
    return Text('${calls.length} calls captured');
  },
);

Listening to new calls in code

Implement XRayNetworkInterceptorListener and register it:

class MyListener implements XRayNetworkInterceptorListener {
  @override
  void onNetworkCallAdded(XRayNetworkCall call) {
    debugPrint('[Network] ${call.method} ${call.uri}${call.responseStatusCode}');
  }
}

final listener = MyListener();
networkInspector.addListener(listener);

// Clean up when done
networkInspector.removeListener(listener);

Finding a call by ID

final call = networkInspector.findById('some-call-id');

Clearing calls

networkInspector.clear();

Custom inspector title

final networkInspector = XRayNetworkInspector(title: 'API Calls');

The title is displayed in the remote UI and used to generate the inspector's ID.

Network call model

Each captured call is an XRayNetworkCall with these fields:

FieldTypeDescription
idStringUnique ID (timestamp-based)
methodStringHTTP method (GET, POST, etc.)
uriStringFull request URI
requestHeadersMap<String, dynamic>?Request headers
requestBodydynamicRequest body
responseStatusCodeint?HTTP status code
responseHeadersMap<String, dynamic>?Response headers
responseBodydynamicResponse body
statusXRayNetworkCallStatusloading / success / error
startTimeDateTimeWhen the request started
endTimeDateTime?When the request completed
durationMsint?Duration in milliseconds
errorString?Error message if failed

Multiple network inspectors

You can run multiple network inspectors simultaneously, each with a distinct title:

final apiInspector = XRayNetworkInspector(title: 'API');
final analyticsInspector = XRayNetworkInspector(title: 'Analytics');

final apiDio = Dio()
  ..interceptors.add(XRayNetworkDioInterceptor(inspector: apiInspector));

final analyticsDio = Dio()
  ..interceptors.add(XRayNetworkDioInterceptor(inspector: analyticsInspector));