dio_speed_tracker
Ein leichtgewichtiger und erweiterbarer Dio-Interceptor zur Überwachung der echten Netzwerkgeschwindigkeit in Mbps basierend auf tatsächlicher HTTP-Download-Leistung
oscarshaitan/dio_speed_tracker open-source repository details.
{"sdk":"flutter"}{"sdk":"flutter"}^1.1.1^2.1.8^1.19.1^5.8.0{"sdk":"flutter"}^5.0.0Englischer Projektschnappschuss. Aktuelle Inhalte auf GitHub.
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.
NetworkStatus.poor when average speed drops below a thresholdAdd this to your pubspec.yaml:
dependencies:
dio: ^5.0.0
collection: ^1.17.2
dio_speed_tracker: ^0.0.3
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),
),
);
speedController.stream.listen((status) {
if (status == NetworkStatus.poor) {
print("🚨 Poor connection detected!");
// Optionally show a UI warning or fallback
}
});
Don't forget to dispose of the controller when no longer needed:
@override
void dispose() {
speedController.dispose();
super.dispose();
}
onReceiveProgress to measure how long a real HTTP download takes.NetworkStatus.poor on the stream.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) | ✅ |
This package includes full unit test coverage for:
flutter test
You’ll find the test files in:
test/
├── network_speed_controller_test.dart
└── speed_interceptor_test.dart
collection package for calculating averagesMIT License — free for personal or commercial use.
Contributions and issues welcome!
If you have improvements or new ideas, feel free to open a PR or start a discussion.