Viewing version 3.0.6. Open the latest package page.

connectivity_plus

3.0.6

Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS.

Download archive

Readme

connectivity_plus

Flutter Community: connectivity_plus

pub package pub points connectivity_plus

This plugin allows Flutter apps to discover network connectivity and configure themselves accordingly. It can distinguish between cellular vs WiFi connection.

Note

On Android, this does not guarantee connection to Internet. For instance, the app might have wifi access but it might be a VPN or a hotel WiFi > with no access.

Platform Support

Android iOS MacOS Web Linux Windows
✔️ ✔️ ✔️ ✔️ ✔️ ✔️

Usage

Sample usage to check current status:

import 'package:connectivity_plus/connectivity_plus.dart';

final connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
  // I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
  // I am connected to a wifi network.
} else if (connectivityResult == ConnectivityResult.ethernet) {
  // I am connected to a ethernet network.
} else if (connectivityResult == ConnectivityResult.vpn) {
  // I am connected to a vpn network.
  // Note for iOS and macOS:
  // There is no separate network interface type for [vpn].
  // It returns [other] on any device (also simulator)
} else if (connectivityResult == ConnectivityResult.bluetooth) {
  // I am connected to a bluetooth.
} else if (connectivityResult == ConnectivityResult.other) {
  // I am connected to a network which is not in the above mentioned networks.
} else if (connectivityResult == ConnectivityResult.none) {
  // I am not connected to any network.
}

Note

You should not be using the current network status for deciding whether you can reliably make a network connection. Always guard your app code against timeouts and errors that might come from the network layer.

You can also listen for network state changes by subscribing to the stream exposed by connectivity plugin:

import 'package:connectivity_plus/connectivity_plus.dart';

@override
initState() {
  super.initState();

  subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
    // Got a new connectivity status!
  });
}

// Be sure to cancel subscription after you are done
@override
dispose() {
  subscription.cancel();
  super.dispose();
}

Note

Connectivity changes are no longer communicated to Android apps in the background starting with Android O (8.0). You should always check for connectivity status when your app is resumed. The broadcast is only useful when your application is in the foreground.

Limitations on the web platform

In order to retrieve information about the quality/speed of a browser's connection, the web implementation of the connectivity plugin uses the browser's NetworkInformation Web API, which as of this writing (June 2020) is still "experimental", and not available in all browsers:

Data on support for the netinfo feature across the major browsers from caniuse.com

On desktop browsers, this API only returns a very broad set of connectivity statuses (One of 'slow-2g', '2g', '3g', or '4g'), and may not provide a Stream of changes. Firefox still hasn't enabled this feature by default.

Fallback to navigator.onLine

For those browsers where the NetworkInformation Web API is not available, the plugin falls back to the NavigatorOnLine Web API, which is more broadly supported:

Data on support for the online-status feature across the major browsers from caniuse.com

The NavigatorOnLine API is provided by dart:html, and only supports a boolean connectivity status (either online or offline), with no network speed information. In those cases the plugin will return either wifi (when the browser is online) or none (when it's not).

Other than the approximate "downlink" speed, where available, and due to security and privacy concerns, no Web browser will provide any specific information about the actual network your users' device is connected to, like the SSID on a Wi-Fi, or the MAC address of their device.

Learn more

Changelog

3.0.6

  • FIX(all): Revert addition of namespace to avoid build fails on old AGPs (#1725).

3.0.5

  • FIX(connectivity_plus): Add compatibility with AGP 8 (Android Gradle Plugin) (#1701).

3.0.4

  • REFACTOR(all): Remove all manual dependency_overrides (#1628).
  • DOCS(connectivity_plus): Documentation added for the missing network interface enums (#1524).

3.0.3

  • FIX: Do not return ConnectivityResult.none on iOS and MacOS with VPN (#1335).
  • DOCS: Updates for READMEs and website pages (#1389).

3.0.2

  • FIX: Add connectivity_plus_web export (#1278).

3.0.1

  • FIX: Increase min Flutter version to fix dartPluginClass registration (#1275).

3.0.0

Note: This release has breaking changes.

  • FIX: lint warnings - add missing dependency for tests (#1233).
  • BREAKING REFACTOR: two-package federated architecture (#1227).

2.3.9

  • CHORE: Version tagging using melos.

2.3.8

  • Discard unused warnings for ensurePathMonitor & ensureReachability call in iOS.

2.3.7

  • iOS: Reduce compiler warnings

2.3.6+1

  • Add issue_tracker link.

2.3.6

  • Web: Fix Bad state: Stream has already been listened to (#943)

2.3.5

  • Stop sending events once flutter engine detached on iOS/macOS (#865)

2.3.4

  • Disables internal use of NetworkInformationAPI which is still experimental

2.3.3

  • macOS: Send events on main thread

2.3.2

  • iOS: Send events on main thread (#846)

2.3.1

  • Update flutter_lints to 2.0.1
  • Update dev dependencies

2.3.0

  • Add iOS ConnectivityProvider based on NWPathMonitor for iOS 12+.

2.2.2

  • Reachability.swift ".unavailable" for iOS is deprecated.

2.2.1

  • Bump nm plugin to 0.5.0 (connectivity_plus_linux)
  • Fix embedding issue in example

2.2.0

  • Add bluetooth as connectivity result. Supported on Android, Linux, and Web

2.1.0

  • Migrated iOS plugin to Swift
  • Removed dependency to old Reachability pod
  • Added dependency to Reachability.swift pod

2.0.3

  • Add Gradle wrapper to Android plugin

2.0.2

  • Fix for error: lambda expressions are not supported in -source 7

2.0.1

  • Upgrade Android compile SDK version
  • Several code improvements

2.0.0

  • Remove deprecated method registerWith (of Android v1 embedding)

1.4.0

  • [MacOS]: Backport to macOS 10.11

1.3.0

  • Add ethernet as connectivity result. Supported on Android, iOS, Windows, Linux, macOS, and Web

1.2.0

  • migrate integration_test to flutter sdk

1.1.0

  • Add ethernet as connectivity result. Supported on Android, Linux, macOS, and Web

1.0.8

  • Web: Fix to show ConnectivityResult.mobile instead of ConnectivityResult.wifi when the network is connected to 4g

1.0.7

  • Android: Fix to detect no-network when Wi-Fi is disconnected on Android M and above

1.0.6

  • Android: Fix unregisterReceiver call for API < N

1.0.5

  • Android: Fix memory leak from registered receiver
  • Android: Fix gradle crash due to previous update in version 1.0.4

1.0.4

  • Android: Add explicit compiler version to avoid warnings

1.0.3

  • Android: migrate to mavenCentral

1.0.2

1.0.1

  • Improve documentation

1.0.0

  • Migrated to null safety

0.8.1

  • Address pub score

0.8.0

  • Add Windows support (connectivity_plus_windows).
  • Removed members that were moved to network_info_plus

0.7.2

  • Deprecated the following members (use network_info_plus instead):
    • getWifiBSSID()
    • getWifiIP()
    • requestLocationServiceAuthorization()
    • getLocationServiceAuthorization()

0.7.1

  • Bump linux version.

0.7.0

  • Add Linux support (connectivity_plus_linux).

0.6.0

  • Fix issue #56: Rename Android and iOS classes and Method Channel to avoid collision with the original connectivity package.

0.5.0

  • Transfer to plus-plugins monorepo

0.4.9+2

  • Update package:e2e to use package:integration_test

0.4.9+1

  • Update package:e2e reference to use the local version in the flutter/plugins repository.

0.4.9

  • Add support for web (by endorsing connectivity_for_web 0.3.0)

0.4.8+6

  • Update lower bound of dart dependency to 2.1.0.

0.4.8+5

0.4.8+4

  • Bump the minimum Flutter version to 1.12.13+hotfix.5.
  • Clean up various Android workarounds no longer needed after framework v1.12.
  • Complete v2 embedding support.
  • Fix CocoaPods podspec lint warnings.

0.4.8+3

  • Replace deprecated getFlutterEngine call on Android.

0.4.8+2

  • Remove hard coded ios workspace setting of the example app.

0.4.8+1

  • Make the pedantic dev_dependency explicit.

0.4.8

  • Adds macOS as an endorsed platform.

0.4.7

  • Migrate the plugin to use the ConnectivityPlatform.instance defined in the connectivity_plus_platform_interface package.

0.4.6+2

  • Migrate deprecated BinaryMessages to ServicesBinding.instance.defaultBinaryMessenger.
  • Bump Flutter SDK to 1.12.13+hotfix.5 or greater (current stable).

0.4.6+1

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Require Flutter SDK 1.10.0 or greater.

0.4.6

  • Add macOS support.

0.4.5+8

  • Update documentation to explain when connectivity updates are received on Android.

0.4.5+7

  • Fix unawaited futures in the example app and tests.

0.4.5+6

  • Fix singleton Reachability problem on iOS.

0.4.5+5

  • Add an analyzer check for the public documentation.

0.4.5+4

  • Stability and Maintainability: update documentations.

0.4.5+3

  • Remove AndroidX warnings.

0.4.5+2

  • Include lifecycle dependency as a compileOnly one on Android to resolve potential version conflicts with other transitive libraries.

0.4.5+1

  • Android: Use android.arch.lifecycle instead of androidx.lifecycle:lifecycle in build.gradle to support apps that has not been migrated to AndroidX.

0.4.5

  • Support the v2 Android embedder.

0.4.4+1

  • Update and migrate iOS example project.
  • Define clang module for iOS.

0.4.4

  • Add requestLocationServiceAuthorization to request location authorization on iOS.
  • Add getLocationServiceAuthorization to get location authorization status on iOS.
  • Update README: add more information on iOS 13 updates with CNCopyCurrentNetworkInfo.

0.4.3+7

  • Update README with the updated information about CNCopyCurrentNetworkInfo on iOS 13.

0.4.3+6

  • [Android] Fix the invalid suppression check (it should be "deprecation" not "deprecated").

0.4.3+5

  • [Android] Added API 29 support for check().
  • [Android] Suppress warnings for using deprecated APIs.

0.4.3+4

  • [Android] Updated logic to retrieve network info.

0.4.3+3

  • Support for TYPE_MOBILE_HIPRI on Android.

0.4.3+2

  • Add missing template type parameter to invokeMethod calls.

0.4.3+1

  • Fixes lint error by using getApplicationContext() when accessing the Wifi Service.

0.4.3

  • Add getWifiBSSID to obtain current wifi network's BSSID.

0.4.2+2

  • Add integration test.

0.4.2+1

  • Bump the minimum Flutter version to 1.2.0.
  • Add template type parameter to invokeMethod calls.

0.4.2

  • Adding getWifiIP() to obtain current wifi network's IP.

0.4.1

  • Add unit tests.

0.4.0+2

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.4.0+1

  • Updated Connectivity to a singleton.

0.4.0

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.3.2

  • Adding getWifiName() to obtain current wifi network's SSID.

0.3.1

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.3.0

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.2.1

  • Fixed warnings from the Dart 2.0 analyzer.
  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.2.0

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.

0.1.1

  • Add FLT prefix to iOS types.

0.1.0

  • Breaking API change: Have a Connectivity class instead of a top level function
  • Introduce ability to listen for network state changes

0.0.1

  • Initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'connectivity_plus:3.0.6'
pubspec.yaml
name: connectivity_plus
description: Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS.
version: 3.0.6
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
issue_tracker: https://github.com/fluttercommunity/plus_plugins/labels/connectivity_plus

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=2.11.0"

flutter:
  plugin:
    platforms:
      android:
        package: dev.fluttercommunity.plus.connectivity
        pluginClass: ConnectivityPlugin
      ios:
        pluginClass: ConnectivityPlusPlugin
      linux:
        dartPluginClass: ConnectivityPlusLinuxPlugin
      macos:
        pluginClass: ConnectivityPlugin
      web:
        pluginClass: ConnectivityPlusWebPlugin
        fileName: src/connectivity_plus_web.dart
      windows:
        pluginClass: ConnectivityPlusWindowsPlugin

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter
  connectivity_plus_platform_interface: ^1.2.4
  js: ^0.6.3
  meta: ^1.8.0
  nm: ^0.5.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: ^2.1.11
  dbus: ^0.7.5
  flutter_lints: ^2.0.1
  mockito: ^5.2.0
  plugin_platform_interface: ^2.1.2
  test: ^1.21.1

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownloadf353f957…ffbeeb
0.5.0Cached · Upstream SHA-256 matchedDownload400133e1…a4e841
0.6.0Cached · Upstream SHA-256 matchedDownloadd95c068e…40b324
0.7.0Cached · Upstream SHA-256 matchedDownloadc90fcf79…0d9575
0.7.1Cached · Upstream SHA-256 matchedDownloadfd9f07b0…f79b5a
0.7.2Cached · Upstream SHA-256 matchedDownload7fb9587d…65bd71
0.8.0Cached · Upstream SHA-256 matchedDownload647e9385…313705
0.8.1Cached · Upstream SHA-256 matchedDownload8d565f7d…c9de03
0.9.0-nullsafety.0Cached · Upstream SHA-256 matchedDownload9c50b950…802ba7
1.0.0Cached · Upstream SHA-256 matchedDownload9bbf5d1a…394a13
1.0.1Cached · Upstream SHA-256 matchedDownload54657e64…d5d25a
1.0.2Cached · Upstream SHA-256 matchedDownload1cdaf133…13c704
1.0.3Cached · Upstream SHA-256 matchedDownloadc2738604…7ab813
1.0.4Cached · Upstream SHA-256 matchedDownload7195b2b9…535aec
1.0.5Cached · Upstream SHA-256 matchedDownload19f93458…193355
1.0.6Cached · Upstream SHA-256 matchedDownload9399efdf…39db45
1.0.7Cached · Upstream SHA-256 matchedDownload3a4653a6…4b81e6
1.0.8Cached · Upstream SHA-256 matchedDownloada3d9a966…830238
1.1.0Cached · Upstream SHA-256 matchedDownload1249fd8d…5d0cc5
1.2.0Cached · Upstream SHA-256 matchedDownloadfcc92da7…c291bb
1.3.0Cached · Upstream SHA-256 matchedDownload7c56bb4d…ba20a4
1.4.0Cached · Upstream SHA-256 matchedDownload77e0b376…b620cc
2.0.0Cached · Upstream SHA-256 matchedDownload81ab0366…35b6aa
2.0.1Cached · Upstream SHA-256 matchedDownloadc4028b19…13179d
2.0.2Cached · Upstream SHA-256 matchedDownload81fb9668…b599d3
2.0.3Cached · Upstream SHA-256 matchedDownloadb5311d90…26d2d3
2.1.0Cached · Upstream SHA-256 matchedDownload63b6c0cf…47908a
2.2.0Cached · Upstream SHA-256 matchedDownload78b23443…be93d1
2.2.1Cached · Upstream SHA-256 matchedDownloadadf46fa1…60328c
2.2.2Cached · Upstream SHA-256 matchedDownload663e5fac…efd46f
2.3.0Cached · Upstream SHA-256 matchedDownload08c3225c…ef6a25
2.3.1Cached · Upstream SHA-256 matchedDownload11b3f4da…bb7cdb
2.3.2Cached · Upstream SHA-256 matchedDownloadb3a377a2…7f5519
2.3.3Cached · Upstream SHA-256 matchedDownload56dfb78c…d03fea
2.3.4Cached · Upstream SHA-256 matchedDownload3ea468d8…175a3b
2.3.5Cached · Upstream SHA-256 matchedDownload60a5c13b…f0a197
2.3.6Cached · Upstream SHA-256 matchedDownloade8eba38c…5c359d
2.3.6+1Cached · Upstream SHA-256 matchedDownloade18bbd02…838d9d
2.3.7Cached · Upstream SHA-256 matchedDownloadc5eb92e2…7edb6d
2.3.8Cached · Upstream SHA-256 matchedDownload979d3b01…bd6908
2.3.9Cached · Upstream SHA-256 matchedDownload3f8fe4e5…7e528e
3.0.0Cached · Upstream SHA-256 matchedDownload3461a36f…d87c0c
3.0.1Cached · Upstream SHA-256 matchedDownloadbe54bbf8…302a3e
3.0.2Cached · Upstream SHA-256 matchedDownload745ebccc…013a22
3.0.3Cached · Upstream SHA-256 matchedDownload8875e8ed…e48e96
3.0.4Cached · Upstream SHA-256 matchedDownloadd73575bb…abc822
3.0.5Cached · Upstream SHA-256 matchedDownload5c7ad2d9…e33e47
3.0.6Cached · Upstream SHA-256 matchedDownloadb74247fa…95c991
4.0.0Cached · Upstream SHA-256 matchedDownload45262924…005991
4.0.1Cached · Upstream SHA-256 matchedDownload8599ae9e…913f34
4.0.2Cached · Upstream SHA-256 matchedDownload77a180d6…95c48b
5.0.0Cached · Upstream SHA-256 matchedDownload94d51c6f…fcf70e
5.0.1Cached · Upstream SHA-256 matchedDownloadb502a681…46f55f
5.0.2Cached · Upstream SHA-256 matchedDownload224a7705…d437f0
6.0.0Cached · Upstream SHA-256 matchedDownloadd3316397…7e9d01
6.0.1Cached · Upstream SHA-256 matchedDownloade9feae83…dad3c9
6.0.2Cached · Upstream SHA-256 matchedDownloadebe15d94…79fc57
6.0.3Cached · Upstream SHA-256 matchedDownloaddb7a4e14…4365b8
6.0.4Cached · Upstream SHA-256 matchedDownload3e7d1d9d…8734f6
6.0.5Cached · Upstream SHA-256 matchedDownload2056db52…7177d0
6.1.0Cached · Upstream SHA-256 matchedDownload87684963…a3e4c3
6.1.1Cached · Upstream SHA-256 matchedDownloade0817759…f9c27d
6.1.2Cached · Upstream SHA-256 matchedDownload8a68739d…938412
6.1.3Cached · Upstream SHA-256 matchedDownload04bf81bb…19ec27
6.1.4Cached · Upstream SHA-256 matchedDownload051849e2…cc1f99
6.1.5Cached · Upstream SHA-256 matchedDownloadb5e72753…ab29ec
7.0.0Cached · Upstream SHA-256 matchedDownload33bae12a…c3973c
7.1.0Cached · Upstream SHA-256 matchedDownloadb8fe5297…166c79
7.1.1Cached · Upstream SHA-256 matchedDownload62ffa266…5ba057
7.2.0Cached · Upstream SHA-256 matchedDownloadcad0e811…313160
7.3.0Cached · Upstream SHA-256 matchedDownload25cebb79…de33cb
7.3.1Cached · Upstream SHA-256 matchedDownload762c99f8…a54bd0
7.3.2Cached · Upstream SHA-256 matchedDownloadd7749fd3…36f741

Dependencies

connectivity_plus_platform_interface "^1.2.4"

flutter { "sdk": "flutter" }

flutter_web_plugins { "sdk": "flutter" }

js "^0.6.3"

meta "^1.8.0"

nm "^0.5.0"