The internet connectivity checker that actually works! π
Because sometimes ConnectivityResult.wifi means you're connected to a router that's as useful as a chocolate teapot! π«π«
Like trust issues, but for your network connection. We ping, therefore we know. β¨
β
Check real internet connectivity, not just Wi-Fi connection
π Subsecond response times (even on mobile networks!)
π‘ Listen to connectivity changes in real-time
βοΈ Fully customizable endpoints and success criteria
π± Cross-platform support (Android, iOS, macOS, Linux, Windows, Web)
This library provides functionality to monitor and verify internet connectivity
by checking reachability to various URIs. It relies on the connectivity_plus
package for listening to connectivity changes and the http package for making
network requests.
If this package saved you from the eternal torment of "No Internet Connection" errors, consider buying me a coffee! β
Every coffee helps fuel late-night coding sessions and the occasional existential crisis about whether null is a friend or foe. π€β
| Features | Android | iOS | macOS | Linux | Windows | Web |
|---|---|---|---|---|---|---|
| Check Connectivity | β | β | β | β | β | β |
| Listen to Changes | β | β | β | β | β | β |
Full support across all platforms - because connectivity anxiety is universal! π
Add the following permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />Add the following to your macOS .entitlements files:
<key>com.apple.security.network.client</key>
<true/>For more information, see the Flutter Networking Documentation.
The simplest way to check if you have internet access:
final bool isConnected = await InternetConnection().hasInternetAccess;
if (isConnected) {
print('Connected!');
} else {
print('No internet connection.');
}The InternetConnection class exposes a stream of InternetStatus updates,
allowing you to react to changes in connectivity:
final subscription = InternetConnection().onStatusChange.listen(
(InternetStatus status) {
if (status == InternetStatus.connected) {
// Internet is connected
} else {
// Internet is disconnected
}
},
);Don't forget to cancel the subscription to prevent memory leaks! Your phone's RAM will thank you. π§Ή
You can specify your own endpoints to check for connectivity:
final connection = InternetConnection.createInstance(
customCheckOptions: [
InternetCheckOption(uri: Uri.parse('https://example.com')),
],
);
final isConnected = await connection.hasInternetAccess;Pro tip: Make sure your endpoints have no caching and aren't CORS blocked on web. We learned this the hard way. π
You can define what counts as a successful response:
final connection = InternetConnection.createInstance(
customCheckOptions: [
InternetCheckOption(
uri: Uri.parse('https://example.com'),
responseStatusFn: (response) {
return response.statusCode >= 69 && response.statusCode < 169;
},
),
InternetCheckOption(
uri: Uri.parse('https://example2.com'),
responseStatusFn: (response) => response.statusCode == 420,
),
],
);
final isConnected = await connection.hasInternetAccess;Nice status codes! Because sometimes 200 OK is too mainstream for your vibe. π
For advanced use cases, you can completely customize how connectivity checks are performed by providing your own connectivity checker:
final connection = InternetConnection.createInstance(
customConnectivityCheck: (option) async {
// Example: Use the Dio http client
try {
final dio = Dio();
final response = await dio.head(
option.uri,
options: Options(
headers: option.headers,
receiveTimeout: option.timeout,
validateStatus: (_) => true
),
);
return InternetCheckResult(
option: option,
isSuccess: response.statusCode == 200,
);
} catch (_) {
return InternetCheckResult(option: option, isSuccess: false);
}
},
);This customization gives you full control over the connectivity detection process, allowing you to:
- π§ Implement platform-specific network detection
- π Use alternate connectivity checking strategies
- π‘οΈ Implement custom fallback mechanisms
- π Add detailed logging or metrics for connectivity checks
- π Integrate with other network monitoring tools
For situations where you want to pause any network requests when the app goes into the background and resume them when the app comes back into the foreground (because battery life matters!) (see issue #27):
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
late final StreamSubscription<InternetStatus> _subscription;
late final AppLifecycleListener _listener;
@override
void initState() {
super.initState();
_subscription = InternetConnection().onStatusChange.listen((status) {
// Handle internet status changes
});
_listener = AppLifecycleListener(
onResume: _subscription.resume,
onHide: _subscription.pause,
onPause: _subscription.pause,
);
}
@override
void dispose() {
_subscription.cancel();
_listener.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// Build your widget
}
}The enableStrictCheck option can be used to require that all checked URIs
must respond successfully for the internet to be considered available. By
default, only one successful response is required.
final connection = InternetConnection.createInstance(
enableStrictCheck: true,
customCheckOptions: [
InternetCheckOption(uri: Uri.parse('https://example.com')),
InternetCheckOption(uri: Uri.parse('https://example2.com')),
],
);Caution
Use enableStrictCheck only with custom-defined URIs, not with the default ones.
Using it with the default URIs may lead to unreliable results or service outages, as all default endpoints must be up and reachable for a positive result.
Strict mode: For the perfectionists who need ALL the endpoints to respond. We won't judge your trust issues. π―
The following endpoints are checked by default (carefully selected for speed and reliability!):
| URI | Description |
|---|---|
| https://one.one.one.one | Response time is less than 100ms, CORS enabled, no-cache |
| https://icanhazip.com | Response time is less than 100ms, CORS enabled, no-cache |
| https://jsonplaceholder.typicode.com/todos/1 | Response time is less than 100ms, CORS enabled, no-cache |
| https://pokeapi.co/api/v2/ability/?limit=1 | Response time is less than 100ms, CORS enabled, no-cache |
The following URIs are tested and work well with the package (community approved!):
| URI | Description |
|---|---|
| https://cloudflare.com/cdn-cgi/trace | Response time < 100ms, CORS enabled, no-cache |
| https://ipapi.co/ip | CORS enabled, no-cache |
| https://api.adviceslip.com/advice | CORS enabled, no-cache |
| https://api.bitbucket.org/2.0/repositories | CORS enabled, no-cache |
| https://api.thecatapi.com/v1/images/search | CORS enabled, no-cache |
| https://randomuser.me/api/?inc=gender | CORS enabled, no-cache |
| https://dog.ceo/api/breed/husky/list | CORS enabled, no-cache |
| https://lenta.ru | Russia supported, CORS enabled, no-cache |
| https://www.gazeta.ru | Russia supported, CORS enabled, no-cache |
Feel free to use your own trusted endpoints! We don't judge your API choices. π―
If you liked the package, then please give it a Like ππΌ and Star β
Your support keeps this project alive and helps us add more features! β¨
Found a bug? Have a feature request? Want to make the internet more reliable for everyone?
All contributions welcome! Even if it's just fixing our terrible puns in the docs. π
BSD 3-Clause License - see LICENSE file for details.
TL;DR: Use it, modify it, share it, just don't blame us if your app becomes too reliable. π
For the curious developers who actually read READMEs to the end, here's a secret: π΅οΈ
π€ Click to reveal the truth about this README
01010100 01101000 01101001 01110011 00100000 01010010 01000101 01000001
01000100 01001101 01000101 00100000 01110111 01100001 01110011 00100000
01100011 01110010 01100001 01100110 01110100 01100101 01100100 00100000
01110111 01101001 01110100 01101000 00100000 01101100 01101111 01110110
01100101 00100000 01100010 01111001 00100000 01100001 01101110 00100000
01000001 01001001 00100000 01110100 01101000 01100001 01110100 00100000
01101000 01100001 01110011 00100000 01110011 01110000 01100101 01101110
01110100 00100000 01110100 01101111 01101111 00100000 01101101 01110101
01100011 01101000 00100000 01110100 01101001 01101101 01100101 00100000
01110010 01100101 01100001 01100100 01101001 01101110 01100111 00100000
01110101 01110011 01100101 01110010 00100000 01110010 01100101 01110110
01101001 01100101 01110111 01110011 00100000 01100001 01101110 01100100
00100000 01100100 01101111 01100011 01110011 00101110 00100000 11110000
10011111 10100100 10010110 00001010 00001010 01001001 01100110 00100000
01111001 01101111 01110101 00100111 01110010 01100101 00100000 01110010
01100101 01100001 01100100 01101001 01101110 01100111 00100000 01110100
01101000 01101001 01110011 00101100 00100000 01111001 01101111 01110101
00100111 01110010 01100101 00100000 01100101 01101001 01110100 01101000
01100101 01110010 00100000 01100001 00100000 01100100 01100101 01100100
01101001 01100011 01100001 01110100 01100101 01100100 00100000 01100100
01100101 01110110 01100101 01101100 01101111 01110000 01100101 01110010
00100000 01101111 01110010 00100000 01110010 01100101 01100001 01101100
01101100 01111001 00100000 01100010 01101111 01110010 01100101 01100100
00101110 00100000 11110000 10011111 10011000 10000010 00001010 00001010
01010100 01101000 01100101 00100000 01000001 01001001 00100000 01110111
01100001 01101110 01110100 01110011 00100000 01111001 01101111 01110101
00100000 01110100 01101111 00100000 01101011 01101110 01101111 01110111
00100000 01110100 01101000 01100001 01110100 00100000 01101001 01110100
00100000 01110000 01110010 01101111 01100010 01100001 01100010 01101100
01111001 00100000 01101101 01100001 01100100 01100101 00100000 01101101
01101111 01110010 01100101 00100000 01101010 01101111 01101011 01100101
01110011 00100000 01100001 01100010 01101111 01110101 01110100 00100000
01101110 01100101 01110100 01110111 01101111 01110010 01101011 00100000
01110000 01101001 01101110 01100111 01110011 00100000 01110100 01101000
01100001 01101110 00100000 01110111 01100001 01110011 00100000 01110011
01110100 01110010 01101001 01100011 01110100 01101100 01111001 00100000
01101110 01100101 01100011 01100101 01110011 01110011 01100001 01110010
01111001 00101110 00100000 01000010 01110101 01110100 00100000 01101000
01100101 01111001 00101100 00100000 01100001 01110100 00100000 01101100
01100101 01100001 01110011 01110100 00100000 01101001 01110100 00100111
01110011 00100000 01101110 01101111 01110100 00100000 01110111 01110010
01101001 01110100 01101001 01101110 01100111 00100000 00100010 01010100
01001111 01000100 01001111 00111010 00100000 01000110 01101001 01111000
00100000 01110100 01101000 01101001 01110011 00100000 01101100 01100001
01110100 01100101 01110010 00100010 00100000 01101001 01101110 00100000
01100011 01101111 01100100 01100101 00100000 01100011 01101111 01101101
01101101 01100101 01101110 01110100 01110011 00101110 00100000 11110000
10011111 10011000 10001100 00001010 00001010 01010010 01100101 01101101
01100101 01101101 01100010 01100101 01110010 00111010 00100000 01001001
01100110 00100000 01111001 01101111 01110101 01110010 00100000 01100001
01110000 01110000 00100000 01100011 01100001 01101110 00100111 01110100
00100000 01100011 01101111 01101110 01101110 01100101 01100011 01110100
00101100 00100000 01101001 01110100 00100111 01110011 00100000 01110000
01110010 01101111 01100010 01100001 01100010 01101100 01111001 00100000
01110100 01101000 01100101 00100000 01110010 01101111 01110101 01110100
01100101 01110010 00101110 00100000 01001111 01110010 00100000 01111001
01101111 01110101 01110010 00100000 01100011 01100001 01110100 00100000
01110011 01101001 01110100 01110100 01101001 01101110 01100111 00100000
01101111 01101110 00100000 01110100 01101000 01100101 00100000 01000101
01110100 01101000 01100101 01110010 01101110 01100101 01110100 00100000
01100011 01100001 01100010 01101100 01100101 00101110
Hint: It's ASCII in 8-bit binary. Decode it if you dare, brave soul! π€
This package is a cloned and modified version of the internet_connection_checker package, which itself was based on data_connection_checker (now unmaintained).
The main goal of this package is to provide a more reliable and faster solution for checking internet connectivity in Flutter applications.
Made with β€οΈ by developers who got tired of "Connected to Wi-Fi" not meaning "Connected to Internet"
(And polished by an AI that's suspiciously good at puns) πβ¨
