net_checker 0.0.5
net_checker: ^0.0.5 copied to clipboard
A lightweight Flutter package to check internet connectivity, monitor connection changes, measure latency, and detect network quality.
net_checker #
A lightweight and cross-platform Flutter package to check internet connectivity, monitor connection changes, measure latency, detect network quality, and identify working hosts.
✨ Features #
| Feature | Supported |
|---|---|
| Internet connectivity check | ✓ |
| Real-time connection monitoring | ✓ |
| Network latency measurement | ✓ |
| Network quality detection | ✓ |
| Working host detection | ✓ |
| Custom host configuration | ✓ |
| UI widgets for connectivity status | ✓ |
| Cross-platform support | ✓ |
📱 Platform Support #
| Platform | Supported | Notes |
|---|---|---|
| Android | ✓ | Requires INTERNET permission |
| iOS | ✓ | No extra permission required |
| Web | ✓ | Limited by browser security (CORS) |
| Windows | ✓ | No extra setup |
| macOS | ✓ | No extra setup |
| Linux | ✓ | No extra setup |
🚀 Installation #
dependencies:
net_checker: ^latest
flutter pub get
📦 Import #
import 'package:net_checker/net_checker.dart';
🔌 Check Internet Connection #
bool connected = await InternetChecker.hasConnection();
🌐 Get Working Host #
String? host = await InternetChecker.getWorkingHost();
⚡ Network Latency #
int? latency = await LatencyChecker.getLatency();
📊 Network Quality #
String quality = await NetworkQuality.getQuality();
🔄 Listen to Connection Changes #
InternetConnectionStream.start().listen((status) {
print(status);
});
⚙️ Custom Configuration #
final config = InternetConfig(
hosts: ["google.com", "cloudflare.com", "1.1.1.1"],
timeout: Duration(seconds: 3),
checkInterval: Duration(seconds: 5),
);
Usage with config #
await InternetChecker.hasConnection(config: config);
await LatencyChecker.getLatency(config: config);
await NetworkQuality.getQuality(config: config);
await InternetChecker.getWorkingHost(config: config);
🧩 Widgets #
Internet Status Indicator #
InternetStatusIndicator()
Internet Status Builder #
InternetStatusBuilder(
builder: (context, status) {
return Text(status.toString());
},
)
No Internet Banner #
NoInternetBanner(visible: true)
⚠️ Platform Configuration #
Android #
Add permission in android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
iOS #
No additional permission required.
If using network calls extensively, ensure App Transport Security allows your endpoints if needed:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Web #
- Uses browser-based network detection
- Subject to CORS and browser security restrictions
- Connectivity checks may not fully match mobile/desktop behavior
- Host verification and latency may be limited
Desktop (Windows / macOS / Linux) #
No additional configuration required.
💡 Best Practices #
- Use default configuration unless needed
- Avoid very low
checkInterval(e.g. < 2 seconds) as it may increase network usage - Use multiple hosts for reliability
Support the Project #
If you find net_checker useful, you can support its development.
📄 License #
MIT License