Skip to main content

internet_status 1.0.0 copy "internet_status: ^1.0.0" to clipboard
internet_status: ^1.0.0 copied to clipboard

Checks whether the device really has internet access (DNS, socket and HTTP), streams the status, and shows an animated offline banner.

internet_status #

Finds out whether the device can really reach the internet, not just whether it is joined to a network. A Wi-Fi network with no route out counts as offline.

It checks three things: a DNS lookup, a socket connection and an HTTP request. You get the result once, or as a stream that updates when the connection changes, and an animated banner you can show when the device goes offline.

This code was part of extensionresoft 1.x. It is its own package so that apps that do not need it do not pull in connectivity_plus and rxdart.

Use it #

import 'package:internet_status/internet_status.dart';

final checker = InternetConnectionChecker();

// once
final online = await checker.isInternetConnected;

// as it changes
checker.onIsInternetConnected.listen((online) {
  // show or hide your own UI
});

// the details: which checks passed, why one failed, and the connection type
checker.onInternetConnectivityChanged.listen((result) {
  print(result.hasInternetAccess);
  print(result.connectionType); // ConnectionType.wifi, mobile, ...
  print(result.failureReason);
});

InternetResult.hasInternetAccess is true only when the DNS, socket and HTTP checks all pass.

ConnectionBanner is a slide-in banner you place in an Overlay or a Stack. Its look is set with ConnectionBannerStyle (colours, icon, height, radius, animation time).

ConnectionBanner(
  message: 'No internet connection',
  style: const ConnectionBannerStyle(),
  onClose: () {/* remove it */},
)

Migrating from extensionresoft 1.x #

extensionresoft 2.0.0 no longer contains these classes. If your app used InternetConnectionChecker, InternetResult, ConnectionBanner or ConnectionBannerStyle:

  1. Add the package:

    dependencies:
      extensionresoft: ^2.0.0
      internet_status: ^1.0.0
    
  2. Change the import in every file that uses them:

    // before
    import 'package:extensionresoft/extensionresoft.dart';
    // after
    import 'package:internet_status/internet_status.dart';
    

The API is unchanged, so no other code needs to change. Keep the extensionresoft import in files that also use its other features. If you stay on extensionresoft ^1.5.1 you do not need this package.

Platform notes #

  • The checks use dart:io, so the package is for Android, iOS, macOS, Windows and Linux, not the web.
  • On Android, connectivity_plus needs the ACCESS_NETWORK_STATE permission (the plugin adds it) and the HTTP check needs INTERNET.
  • On iOS and macOS a VPN connection may be reported as ConnectionType.other.

License #

BSD-3-Clause, see LICENSE.

4
likes
160
points
32
downloads

Documentation

API reference

Publisher

verified publisherkenresoft.com

Weekly Downloads

Checks whether the device really has internet access (DNS, socket and HTTP), streams the status, and shows an animated offline banner.

Repository (GitHub)
View/report issues

Topics

#connectivity #network #internet #offline #banner

License

BSD-3-Clause (license)

Dependencies

connectivity_plus, flutter, rxdart

More

Packages that depend on internet_status