Тhere are several Dart/Flutter packages available for detecting slow internet connections. These typically work by pinging servers or measuring response times, rather than just checking if a connection exists (which connectivity_plus handles but doesn’t quantify speed or slowness). Below, I’ll highlight the most relevant ones based on popularity, features, and ease of use.
Recommended Packages
| Package | Description | Key Features for Slow Connection Detection | Pub.dev Link |
|---|---|---|---|
| internet_connection_checker | A reliable library for checking internet availability and explicitly detecting slow connections via configurable timeouts. | – Enable slow detection with SlowConnectionConfig (e.g., threshold of 1 second).– Customizable pings to multiple addresses. – Streams for real-time changes. – Handles auto-refresh on reconnection. |
pub.dev/packages/internet_connection_checker |
| network_speed | Real-time speed monitoring plugin for Android/iOS. | – Continuous speed updates (download/upload). – Network type detection (WiFi/mobile). – Uses native APIs for precision. – Define “slow” based on thresholds (e.g., < 1 Mbps). |
pub.dev/packages/network_speed |
| flutter_internet_speed_test | Performs full speed tests with progress callbacks. | – Measures download/upload speeds. – Server selection and error handling. – Custom file sizes for tests. – Detect slow by comparing results to benchmarks. |
pub.dev/packages/flutter_internet_speed_test |
| internet_speed_test | Simple plugin for on-demand speed tests. | – Integrates easily for spot-checks. – Returns Mbps values. – Useful for one-off “slow” detection before API calls. |
pub.dev/packages/internet_speed_test |
Quick Implementation Example (Using internet_connection_checker)
Add to pubspec.yaml:
dependencies:
internet_connection_checker: ^1.0.0 # Check latest version
Basic usage to detect slow connections:
import 'package:internet_connection_checker/internet_connection_checker.dart';
void checkConnection() async {
final checker = InternetConnectionChecker.createInstance(
slowConnectionConfig: SlowConnectionConfig(
enableToCheckForSlowConnection: true,
slowConnectionThreshold: const Duration(seconds: 2), // Adjust threshold for "slow"
),
);
final result = await checker.hasConnection;
if (result) {
print('Connected (fast or slow)');
final isSlow = await checker.isConnectionSlow; // Explicit slow check
print('Slow connection: $isSlow');
} else {
print('No connection');
}
checker.dispose(); // Clean up
}
Other Utilities
- Custom HTTP-based check: No package needed—use
httppackage to download a small file (e.g., 100KB) and calculate speed (bytes / time). See GeeksforGeeks tutorial for code. - connectivity_plus: Great for basic connectivity (WiFi/mobile/none), and web support includes rough speed categories like ‘slow-2g’. But pair it with a speed tester for true “slow” detection.
For production, start with internet_connection_checker—it’s lightweight and directly addresses slow detection. Test on real devices, as emulators can skew results.
Internet_connection_checker_plus package (version 2.9.1) does not have built-in functionality for explicitly detecting slow internet connections, such as an isConnectionSlow method or a configurable SlowConnectionConfig like its predecessor (internet_connection_checker).
Key Details from the Package
- Core Functionality: It excels at checking internet reachability via pings to configurable URIs (e.g.,
hasInternetAccessfor one-time checks oronStatusChangestream for real-time updates). It supports custom timeouts inInternetCheckOptionand custom success criteria (e.g., response status codes or even a full custom checker using Dio). - Slow Detection Limitations: While you can implement slow detection manually (e.g., by measuring response times in a
customConnectivityCheckfunction and setting thresholds), there’s no out-of-the-box support for it. This makes it less plug-and-play for your use case compared to the original package. - Migration Note: This is a fork/rewrite of
internet_connection_checker, but it dropped the explicit slow-check features to focus on speed and customization. If slow detection is essential, stick with the original or explorenetwork_speedas I mentioned earlier.
