The Internet Connection Checker is a Flutter package designed to swiftly verify your internet connection, even on mobile networks, with subsecond response times.
This library equips you with the capability to monitor and validate internet connectivity by assessing reachability to various Uris. It leverages the connectivity_plus package for tracking connectivity alterations and the http package for executing network requests.
- Determine internet connectivity status
- Observe alterations in internet connectivity
| Platform | Check Connectivity | Listen for Changes |
|---|---|---|
| Android | ✅ | ✅ |
| iOS | ✅ | ✅ |
| macOS | ✅ | ✅ |
| Linux | ✅ | ✅ |
| Windows | ✅ | ✅ |
| Web | ✅ | ✅ |
In your AndroidManifest.xml file, include the following permissions:
<uses-permission android:name="android.permission.INTERNET" />Add the following permissions to your macOS .entitlements files:
<key>com.apple.security.network.client</key>
<true/>
For further details, consult the Flutter Networking Documentation.
Append the internet_connection_checker package to your pubspec.yaml file:
dependencies:
internet_connection_checker: ^2.1.0Integrate the internet_connection_checker_plus package into your Dart file:
import 'package:internet_connection_checker/internet_connection_checker.dart';The easiest way to examine internet connectivity is by employing the InternetConnection class:
bool result = await InternetConnection().hasInternetAccess;The InternetConnection class also delivers a stream of InternetStatus that can be utilized to monitor shifts in internet connectivity:
final listener = InternetConnection().onStatusChange.listen((InternetStatus status) {
switch (status) {
case InternetStatus.connected:
// The internet is now connected
break;
case InternetStatus.disconnected:
// The internet is now disconnected
break;
}
});Remember to cancel the subscription when it's no longer needed. This prevents memory leaks and frees up resources:
listener.cancel();You can configure the InternetConnection class to evaluate custom Uris for internet connectivity:
final connection = InternetConnection.createInstance(
customCheckOptions: [
InternetCheckOption(uri: Uri.parse('https://example.com')),
],
);The InternetConnection class defaults to the following Uris:
| URI | Description |
|---|---|
https://icanhazip.com |
Response time is less than 100ms, CORS enabled, no-cache |
https://jsonplaceholder.typicode.com/posts/1 |
Response time is less than 100ms, CORS enabled, no-cache |
https://pokeapi.co/api/v2/pokemon/1 |
Response time is less than 100ms, CORS enabled, no-cache |
https://reqres.in/api/users/1 |
Response time is less than 100ms, CORS enabled, no-cache |
| URI | Description |
|---|---|
https://ifconfig.me/ip |
Payload is less than 50 bytes, CORS enabled, no-cache |
https://ipecho.net/plain |
Payload is less than 50 bytes, CORS enabled, no-cache |
https://lenta.ru |
Russia supported, CORS enabled, no-cache |
https://www.gazeta.ru |
Russia supported, 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://www.boredapi.com/api/activity |
CORS enabled, no-cache |
https://api.thecatapi.com/v1/images/search |
CORS enabled, no-cache |
https://api.coindesk.com/v1/bpi/currentprice.json |
CORS enabled, no-cache |
This package is a cloned and modified version of the internet_connection_checker package, which itself is a cloned and modified version of the data_connection_checker package, which is no longer actively maintained.
The goal of this package is to offer support for the web platform, a feature currently absent in the internet_connection_checker package.