NetworkTracker class

Tracks network request performance.

Use trackRequest / completeRequest for manual tracking, or trackHttpCall to wrap an async HTTP call.

Example with the http package:

final response = await networkTracker.trackHttpCall(
  'https://api.example.com/data',
  () => http.get(Uri.parse('https://api.example.com/data')),
  extractStatusCode: (r) => r.statusCode,
);

Example with Dio:

final response = await networkTracker.trackHttpCall(
  'https://api.example.com/data',
  () => dio.get('https://api.example.com/data'),
  extractStatusCode: (r) => r.statusCode ?? 0,
);

Constructors

NetworkTracker()

Properties

averageLatencyMs double
Average latency in milliseconds across completed requests.
no setter
failedRequests int
Number of failed requests (status >= 400 or error).
no setter
hashCode int
The hash code for this object.
no setterinherited
requests List<NetworkRequestRecord>
Unmodifiable view of all tracked requests.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalRequests int
Total number of tracked requests.
no setter

Methods

completeRequest(NetworkRequestRecord record, {required int statusCode}) → void
Mark a tracked request as complete.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Clear all tracked requests.
toString() String
A string representation of this object.
inherited
trackHttpCall<T>(String url, Future<T> call(), {String method = 'GET', int extractStatusCode(T response)?}) Future<T>
Convenience wrapper that tracks an asynchronous HTTP call.
trackRequest(String url, {String method = 'GET'}) NetworkRequestRecord
Start tracking a new request. Returns the record to pass to completeRequest when the request finishes.

Operators

operator ==(Object other) bool
The equality operator.
inherited