internet_connection_checker_plus library

A utility package for checking internet connectivity status in Flutter applications.

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.


Usage


Checking for internet connectivity

The simplest way to check for internet connectivity is to use the InternetConnection class.

import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';

bool result = await InternetConnection().hasInternetAccess;

Listening for internet connectivity changes

The InternetConnection class also provides a Stream of InternetStatuses that can be used to listen for changes in internet connectivity.

import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';

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;
    }
  },
);

Don't forget to cancel the subscription when it is no longer needed. This will prevent memory leaks and free up resources.

listener.cancel();

Classes

InternetCheckOption
Options for checking the internet connectivity to an address.
InternetCheckResult
Represents the result of an internet connection check.
InternetConnection
A utility class for checking internet connectivity status.

Enums

InternetStatus
Enum representing the status of internet connectivity.

Typedefs

ResponseStatusFn = bool Function(Response response)
A Callback Function to decide whether the request succeeded or not.