dio_speed_tracker 0.0.2 copy "dio_speed_tracker: ^0.0.2" to clipboard
dio_speed_tracker: ^0.0.2 copied to clipboard

A lightweight and extensible Dio interceptor for monitoring real-world network speed in Mbps, based on actual HTTP download performance. Emits NetworkStatus.poor when the average speed drops below a c [...]

dio_speed_tracker #

A lightweight and extensible Dio interceptor that tracks real-world network download speeds in Mbps, using actual HTTP responses instead of ICMP pings.

This is a practical alternative to custom_ping, ideal for apps where ICMP (ping) is blocked or unreliable โ€” or when you want real-world performance metrics rather than synthetic ones.


๐Ÿ” Features #

  • โœ… Dio interceptor that measures network speed from actual downloads
  • ๐Ÿ“‰ Emits NetworkStatus.poor when average speed drops below a threshold
  • ๐Ÿ”„ Rolling average for smoothing out results
  • โš™๏ธ Configurable sample size, duration, and thresholds
  • ๐Ÿงฉ No platform channels or native code needed
  • ๐Ÿ‘Œ Suitable for Flutter & Dart web/server apps alike

๐Ÿ“ฆ Installation #

Add this to your pubspec.yaml:

dependencies:
  dio: ^5.0.0
  collection: ^1.17.2
  dio_speed_tracker:
    git:
      url: https://github.com/your-username/dio_speed_tracker.git

๐Ÿš€ Usage #

1. Create and attach the interceptor #

final speedController = NetworkSpeedController(
  maxSpeedSamples: 10,
  minResultsToCheck: 5,
  poorConnectionThreshold: 2.0, // Mbps
);

final dio = Dio();

dio.interceptors.add(
  SpeedInterceptor(
  speedController,
  minTrackableSize: 10 * 1024, // 10 KB
  minDuration: Duration(milliseconds: 20),
  ),
);

2. Listen for connection quality #

speedController.stream.listen((status) {
  if (status == NetworkStatus.poor) {
    print("๐Ÿšจ Poor connection detected!");
    // Optionally show a UI warning or fallback
  }
});

3. Clean up #

Don't forget to dispose of the controller when no longer needed:

@override
void dispose() {
  speedController.dispose();
  super.dispose();
}

๐Ÿ“Š How It Works #

  • The interceptor uses Dio's onReceiveProgress to measure how long a real HTTP download takes.
  • It calculates Mbps based on size and duration.
  • Speeds are stored in a rolling buffer, and the average is continuously evaluated.
  • When the average falls below the defined threshold, it emits NetworkStatus.poor on the stream.

๐Ÿ†š Why Not custom_ping? #

Unlike custom_ping:

Feature dio_speed_tracker custom_ping
Real download-based speed โœ… โŒ
Works without ICMP permissions โœ… โŒ
Cross-platform compatible โœ… ๐Ÿšซ (native)
Dio integration โœ… โŒ
No extra request calls โœ… โŒ
Single request evaluation โŒ (TBD) โœ…

๐Ÿงช Testing #

This package includes full unit test coverage for:

  • Speed sample tracking and averaging
  • Rolling window logic
  • Threshold stream emission
  • Basic interceptor setup

Run tests: #

flutter test

Youโ€™ll find the test files in:

test/
โ”œโ”€โ”€ network_speed_controller_test.dart
โ””โ”€โ”€ speed_interceptor_test.dart

๐Ÿงฐ Requirements #

  • Dart 2.17+
  • Dio 5+
  • collection package for calculating averages

๐Ÿ“‚ License #

MIT License โ€” free for personal or commercial use.


๐Ÿ™Œ Contributing #

Contributions and issues welcome!
If you have improvements or new ideas, feel free to open a PR or start a discussion.


4
likes
0
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight and extensible Dio interceptor for monitoring real-world network speed in Mbps, based on actual HTTP download performance. Emits NetworkStatus.poor when the average speed drops below a customizable threshold. Unlike custom_ping, this works in restricted environments without requiring ICMP (ping) support.

Repository (GitHub)
View/report issues

Topics

#network #dio #performance #connection #speed

Documentation

Documentation

License

unknown (license)

Dependencies

collection, dio, flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on dio_speed_tracker