connectivity_validator
Flutter plugin for validated internet connectivity: real internet access, not just “network connected.” Detects captive portals and router-without-internet. Stream-based, Android, iOS & macOS.
Features
- Validated connectivity (real internet, not only link up)
- Captive portal and “WiFi on, no internet” detection
- Real-time stream (
onConnectivityChanged) - Android (API 24+), iOS (12.0+) and macOS (10.14+)
Why connectivity_validator?
Most connectivity packages tell you whether a network interface is up — not whether you can actually reach the internet. So your app shows “online” while stuck behind a hotel WiFi login page, or when the router has lost its upstream connection.
connectivity_validator answers the question you actually care about: can the device
reach the internet right now? It combines native OS validation
(NET_CAPABILITY_VALIDATED on Android, NWPathMonitor on iOS) with a lightweight HTTPS
probe to generate_204 endpoints, so a captive portal or dead router reports as offline.
connectivity_plus |
internet_connection_checker |
connectivity_validator | |
|---|---|---|---|
| Network interface up | ✅ | ✅ | ✅ |
| Real internet reachable | ❌ | ✅ | ✅ |
| Captive portal detected | ❌ | ❌ | ✅ |
| Native OS validation | ❌ | ❌ | ✅ |
| Real-time stream | ✅ | ✅ | ✅ |
Installation
pubspec.yaml
dependencies:
connectivity_validator: ^0.0.8
flutter pub get
Platform setup
Android — Add to AndroidManifest.xml if needed:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
iOS
- Swift Package Manager (default) — No extra setup. Flutter uses SPM for the plugin.
- CocoaPods — If your project uses CocoaPods for this plugin, run in the project root:
cd ios && pod install && cd ..
macOS — The app sandbox blocks outgoing requests by default, so the HTTPS
validation probe needs the network client entitlement. Add it to both
macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements:
<key>com.apple.security.network.client</key>
<true/>
Without this the plugin always reports offline on macOS.
Usage
import 'package:connectivity_validator/connectivity_validator.dart';
final validator = ConnectivityValidator();
validator.onConnectivityChanged.listen((isOnline) {
if (isOnline) {
// Internet validated
} else {
// No internet or captive portal
}
});
Get initial state and listen to changes:
final validator = ConnectivityValidator();
// Get initial state
final initialStatus = await validator.onConnectivityChanged.first;
print('Initial status: ${initialStatus ? "Online" : "Offline"}');
// Listen to changes
validator.onConnectivityChanged.listen((isOnline) {
print('Connectivity changed: ${isOnline ? "Online" : "Offline"}');
});
Live status (stream) + manual check (on-demand):
final validator = ConnectivityValidator();
// Live updates
validator.onConnectivityChanged.listen((isOnline) => /* update UI */);
// On-demand check (e.g. button tap)
final isOnline = await validator.getConnectivityStatus;
In UI (e.g. StreamBuilder):
StreamBuilder<bool>(
stream: ConnectivityValidator().onConnectivityChanged,
initialData: false,
builder: (context, snapshot) {
final isOnline = snapshot.data ?? false;
return Text(isOnline ? 'Online' : 'Offline');
},
)
Run the example:
cd example && flutter pub get && flutter run
Documentation
- State management (GetX, Provider, Riverpod, BLoC, ValueNotifier)
- API reference
- How it works
- Best practices
- Troubleshooting
Contributing
Contributions welcome. See the GitHub repo.
License
See LICENSE.