internet_connection_checker_service 1.1.4+1 copy "internet_connection_checker_service: ^1.1.4+1" to clipboard
internet_connection_checker_service: ^1.1.4+1 copied to clipboard

A service for checking internet connection status and accessibility

Pub

Introduction #

This package provides methods and streams for checking the current internet connection status and whether internet access is available through specified URLs.

Features #

  • Check the current internet connection status: disconnected or connected.
  • Determine the internet connection through specific URLs.

Platform notes #

Some platforms require additional steps, as detailed below.

Android #

Android apps must declare their use of the internet in the Android manifest (AndroidManifest.xml ):

<manifest xmlns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <application ...
</manifest>

macOS #

macOS apps must allow network access in the relevant .entitlements files.

<key>com.apple.security.network.client</key>
<true/>

Learn more about setting up entitlements.

Usage #

To use this package, make sure to include it in your pubspec.yaml file:

dependencies:
  internet_connection_checker_service: ^1.1.4+1

Example usage:

final internetConnectionChecker = InternetConnectionCheckerService();

List<InternetConnectionOptions> optionURLs = [
    const InternetConnectionOptions(
      uri: 'https://google.com',
      timeout: Duration(seconds: 20),
    ),
    const InternetConnectionOptions(
      uri: 'https://bing.com',
      timeout: Duration(seconds: 20),
    ),
  ];


// Get the current internet connection status.
final status = await internetConnectionChecker.connectionStatus;

// Listen to changes in internet connection status.
StreamSubscription<InternetConnectionStatus>? _streamSubscription;

_streamSubscription = internetConnectionChecker
    .onInternetConnectionStatusChanged(optionURLs: optionURLs)
    .listen((status) {
  // Handle the internet connection status change.
});

// Check if internet access is available through specified URLs.
final hasAccess = await internetConnectionChecker.hasInternetAccess(
  optionURLs: optionURLs,
);

// Note that the optionURLs parameter is optional and can be omitted.

Additional information #

I conducted research on packages that rely on connectivity_plus and noticed that they do not accurately detect changes in internet connectivity. As a result, I decided to develop a new package inspired by internet_connection_checker to address these issues and provide more reliable internet connection change detection.

If you have more specific details or questions related to creating this package or need further assistance, please feel free to ask.

3
likes
130
pub points
47%
popularity

Publisher

unverified uploader

A service for checking internet connection status and accessibility

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

connectivity_plus, dio, flutter

More

Packages that depend on internet_connection_checker_service