A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.

Overview

cross_connectivity

Build Pub GitHub GitHub stars

A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.

Getting Started

In order to use this plugin, add dependency in the pubspec.yaml:

cross_connectivity: any

or

cross_connectivity:
    git:
      url: https://github.com/marchdev-tk/cross_connectivity

Add an import to dart file:

import 'package:cross_connectivity/cross_connectivity.dart';

Samples

Web sample:

Web Sample

Desktop sample:

Desktop Sample

Mobile sample:

Mobile Sample

Usage

Functional approach

This plugin provides two streams:

  • isConnected that shows whether the device is REALLY connected to the network or not.
  • onConnectivityChanged that it will not let you know about state of the REAL network connection. It only shows connectivity state.

Also for one time check could be used following methods:

  • checkConnection() that is working like isConnected, but returns Future<bool> instread of Stream<bool>.
  • checkConnectivity() that is working like onConnectivityChanged, but returns Future<ConnectivityStatus> instread of Stream<ConnectivityStatus>.

There are no more methods (they are working only on Android/iOS/macOS):

  • getWifiName() - Obtains the wifi name (SSID) of the connected network.
  • getWifiBSSID() - Obtains the wifi BSSID of the connected network.
  • getWifiIP() - Obtains the IP address of the connected wifi network.

They are removed to wifi_info_flutter.

Migration guide:

If you don't use any of the above APIs, your code should work as is. In addition, you can also remove NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription in ios/Runner/Info.plist

If you use any of the above APIs, you can find the same APIs in the wifi_info_flutter plugin. For example, to migrate getWifiName, use the new plugin:

final WifiInfo _wifiInfo = WifiInfo();
final String wifiName = await _wifiInfo.getWifiName();

Widget approach

As an alteration to funcitonal approach could be used ConnectivityBuilder widget as follows:

ConnectivityBuilder(
  builder: (context, isConnected, status) => Row(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Icon(
        isConnected == true
            ? Icons.signal_wifi_4_bar
            : Icons.signal_wifi_off,
        color: isConnected == true ? Colors.green : Colors.red,
      ),
      const SizedBox(width: 8),
      Text(
        '$status',
        style: TextStyle(
          color: status != ConnectivityStatus.none
              ? Colors.green
              : Colors.red,
        ),
      ),
    ],
  ),
)

Feature requests and Bug reports

Feel free to post a feature requests or report a bug here.

Comments
  • Migrate from connectivity to connectivity_plus

    Migrate from connectivity to connectivity_plus

    The Flutter connectivity plugin has been deprecated.

    Per: https://pub.dev/packages/connectivity the Flutter team's recommendation is to migrate to the connectivity_plus plugin.

    This is an automated PR sent by LSCBot. LSCBot is a service that performs maintenance tasks across many repositories. To make sure you get all the maintenance help LSCBot has to offer - register your repository at lscbot.com.

    opened by lscbot 2
  • Null pointer exception in 3.0.1

    Null pointer exception in 3.0.1

    After upgrading to 3.0.1 I've encountered NPE in connectivity.widget.dart line 63 where there is _connectivity.isConnected.valueWrapper!.value. The valueWrapper is obviously null at the moment. I've fixed this on my local instalation by changing the code to _connectivity.isConnected.valueWrapper?.value ?? false. It works fine, but I won't make a PR for this change as I'm not 100% sure this is the right solution. I hope it is. Please fix this issue either by implementing my code or other way.

    opened by edlman 2
  • Null safety

    Null safety

    Description

    Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change. If you're changing visual properties, consider including before/after screenshots (and runnable code snippets to reproduce them).

    Related Issues

    Replace this paragraph with a list of issues related to this PR from our issue database. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.

    Tests

    I added the following tests:

    Replace this with a list of the tests that you added as part of this PR. A change in behaviour with no test covering it will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See Test Coverage.

    Checklist

    Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

    • [ ] I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
    • [ ] I updated/added relevant documentation (doc comments with ///).
    • [ ] All existing and new tests are passing.
    • [ ] The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
    • [ ] I am willing to follow-up on review comments in a timely manner.

    Breaking Change

    Did any tests fail when you ran them?

    • [ ] No, no existing tests failed, so this is not a breaking change.
    • [ ] Yes, this is a breaking change. If not, delete the remainder of this section.
      • [ ] I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
      • [ ] I got input from the developer relations team, specifically from: Replace with the names of who gave advice
      • [ ] I wrote a migration guide: Replace with a link to your migration guide
    opened by dmk-rib 2
  • Remove embedded print(isConnected)

    Remove embedded print(isConnected)

    Thank for the well thought of package, and for exposing connection values as a stream!

    Would it be possible to get rid of print(isConnected) at connectivity_service.web.dart L19?

    Thanks ;)

    proposal platform-web 
    opened by 1N50MN14 2
  • W/FlutterJNI(13146): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.flutter.io/connectivity_status. Response ID: 0

    W/FlutterJNI(13146): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.flutter.io/connectivity_status. Response ID: 0

    This erros appears when a toggle the celular internet.

    W/FlutterJNI(13146): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.flutter.io/connectivity_status. Response ID: 0

    [√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [versão 10.0.19043.1237], locale pt-BR)
        • Flutter version 2.5.2 at C:\Ferramentas\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 3595343e20 (7 days ago), 2021-09-30 12:58:18 -0700
        • Engine revision 6ac856380f
        • Dart version 2.14.3
    
    [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at C:\Users\AMcom\AppData\Local\Android\Sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_SDK_ROOT = C:\Users\AMcom\AppData\Local\Android\Sdk
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    
    [√] Android Studio (version 2020.3)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin can be installed from:
           https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
           https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [√] IntelliJ IDEA Ultimate Edition (version 2021.2)
        • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.1
        • Flutter plugin version 60.1.4
        • Dart plugin version 212.5080.8
    
    [√] VS Code (version 1.60.2)
        • VS Code at C:\Users\AMcom\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.27.0
    
    [√] Connected device (2 available)
        • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
        • Edge (web)                         • edge          • web-javascript • Microsoft Edge 94.0.992.38
    
    opened by lucasdidur 1
  • Is there any time delay for isConnected steam ?

    Is there any time delay for isConnected steam ?

    Hi, Is there any time delay or interval for isConnected stream to trigger? When i turned off and turn on the wifi, it is triggering after couple of seconds.

    Thanks.

    opened by sureace 1
  • Update libs

    Update libs

    Description

    Update libs: meta, http, rxdart

    Checklist

    Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

    • [x] I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
    • [x] I updated/added relevant documentation (doc comments with ///).
    • [x] All existing and new tests are passing.
    • [x] The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
    • [x] I am willing to follow-up on review comments in a timely manner.

    Breaking Change

    Did any tests fail when you ran them?

    • [x] No, no existing tests failed, so this is not a breaking change.
    • [ ] Yes, this is a breaking change. If not, delete the remainder of this section.
      • [ ] I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
      • [ ] I got input from the developer relations team, specifically from: Replace with the names of who gave advice
      • [ ] I wrote a migration guide: Replace with a link to your migration guide
    opened by otopba 1
  • Use connectivity 2.0.0

    Use connectivity 2.0.0

    Description

    Upgrade to connectivity 2.0.0

    • [x] I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
    • [x] I updated/added relevant documentation (doc comments with ///).
    • [x] All existing and new tests are passing.
    • [x] The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
    • [x] I am willing to follow-up on review comments in a timely manner.

    Breaking Change

    Did any tests fail when you ran them?

    • [ ] No, no existing tests failed, so this is not a breaking change.
    • [x] Yes, this is a breaking change. If not, delete the remainder of this section.
      • [ ] I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
      • [ ] I got input from the developer relations team, specifically from: Replace with the names of who gave advice
      • [x] I wrote a migration guide: -> in the changelog
    opened by cbenhagen 0
  • Failure to detect mobile internet in Android 5.1.1

    Failure to detect mobile internet in Android 5.1.1

    Hi . We try connect to internet by mobile-Internet In Android 5.1.1 on the real device .In fact, the code I tested is the same as the sample code in the repository. But Library can't detect internet connection.

    wontfix 
    opened by esmaeil-ahmadipour 0
  • Question - What you mean with

    Question - What you mean with "REAL Connection state"

    What diference exist between you package and connectivity_plus package?

    Do you package make some ping test or another type of test to check if device is online?

    What you mean with "REAL Connection state" in readme?

    opened by filipenanclarez 1
  • Widget test failing

    Widget test failing

    We've got a very simple widget test that passes fine, however once we've added the ConnectivityBuilder to the top of the widget tree in that test, the test fails with this error:

    2021-11-06_14-53-00

    How can we resolve this widget test error ?

      testWidgets('MslDrawer banner text is correct', (WidgetTester tester) async {
        _authService.setAuthUser(AuthUser(
          authSystemUid: 'x',
          authSystem: 'x',
          firstName: 'x',
          lastName: 'x',
        ));
    
        await tester.pumpWidget(
          MaterialApp(
            home: MslDrawer(),
          ),
        );
    
        expect(find.text('Version'), findsOneWidget);
      });
    
    question 
    opened by SogoGolf 0
Owner
MarchDev Toolkit
Code with ease via MarchDev Toolkit
MarchDev Toolkit
A cross-platform (Android/Windows/macOS/Linux) USB plugin for Flutter

quick_usb A cross-platform (Android/Windows/macOS/Linux) USB plugin for Flutter Usage List devices List devices with additional description Get device

Woodemi Co., Ltd 39 Oct 1, 2022
A Flutter plugin to read 🔖 metadata of 🎵 media files. Supports Windows, Linux & Android.

flutter_media_metadata A Flutter plugin to read metadata of media files. A part of Harmonoid open source project ?? Install Add in your pubspec.yaml.

Harmonoid 60 Dec 2, 2022
Connectionstatusbar - Flutter connection status bar, widget that animates when internet connection changes

connection_status_bar A widget that animates when internet connection changes Getting Started add it to your dependencies then use it anywhere on your

Amir Ghezelbash 112 Nov 23, 2022
🎞 Flutter media playback, broadcast & recording library for Windows, Linux & macOS. Written in C++ using libVLC & libVLC++. (Both audio & video)

dart_vlc Flutter media playback, broadcast, recording & chromecast library for Windows, Linux & macOS. Written in C++ using libVLC & libVLC++. Install

Hitesh Kumar Saini 417 Dec 29, 2022
Music reader for online data (Google Drive implementation). Cross platform goal : iOS, Android, MacOS, Windows

omusic A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this i

JeanNicolasdeLamballerie 0 Nov 30, 2021
🎵 Elegant music app to play local music & YouTube music. Distributes music into albums & artists. Has playlists & lyrics. Windows + Linux + Android.

Harmonoid Elegant music app to play local music & YouTube music. Download Now ?? Windows, Linux & Android. Feel free to report bugs & issues. Loving t

Harmonoid 1.9k Aug 10, 2022
✈️ A tidy utility to handle offline/online connectivity like a Boss

✈️ Flutter Offline A tidy utility to handle offline/online connectivity like a Boss. It provides support for both iOS and Android platforms (offcourse

Jeremiah Ogbomo 845 Jan 2, 2023
A better Minecraft Launcher that supports multiple platforms and many functionalities for you to explore!

A better Minecraft Launcher that supports multiple platforms and many functionalities for you to explore!

RPMTW Team 74 Dec 14, 2022
Sharezone is a collaborative school organization app for iOS, Android, macOS and web.

Download Sharezone Android iOS macOS Web Sharezone is a collaborative school organization app for iOS, Android, macOS and web. With Sharezone pupils,

Sharezone 93 Dec 18, 2022
Flutter window blur & transparency effects for on Windows & Linux. 💙

flutter_acrylic Window blur & transparency effects for Flutter on Windows & Linux Installation Mention in your pubspec.yaml. dependencies: ... flu

Hitesh Kumar Saini 438 Jan 2, 2023
Plugin to checker data connection network.

ci_connectivity OBS: For now we don't have IOS support Getting Started Flutter plugin for checking network connection. It is not just checking if you

Lucas Firmino 0 Nov 23, 2021
A Flutter plugin that supports Pangle SDK on Android and iOS.

Thanks for non-commercial open source development authorization by JetBrains. 穿山甲 Flutter SDK `pangle_flutter`是一款集成了字节跳动穿山甲 Android 和 iOS SDK的 Flutter

null 121 Dec 2, 2022
A robust Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS

?? Paystack Plugin for Flutter A Flutter plugin for making payments via Paystack Payment Gateway. Fully supports Android and iOS. ?? Installation To u

Wilberforce Uwadiegwu 165 Jan 4, 2023
A flutter plugin for integrating razorpay payment gateway. Supports Android and iOS.

Flutter Razorpay Plugin A flutter plugin for razorpay integration for both android and ios. If you use this library in your app, please let me know an

Chetan Kaushik 28 Dec 13, 2022
Audio manager - A flutter plugin for music playback, including notification handling.

audio_manager A flutter plugin for music playback, including notification handling. This plugin is developed for iOS based on AVPlayer, while android

Jerome Xiong 96 Oct 25, 2022
Unofficial Bavatar dart app for android, iOS and macOS

Unofficial Bavatar dart app for android, iOS and macOS Generated by the Very Good CLI ?? Getting Started ?? This project contains 3 flavors: developme

Pishure 3 Jul 12, 2021
Hybrid App build on flutter SDK able to run on Android, IOS, web, desktop

Codeforces Visualizer APP Ready to use Flutter Application. Uses codeforces API. Useful for codeforces programmers. ScreenShots Single User Page Compa

vikas yadav 13 Dec 31, 2022
Learn to build apps that work on Android, iOS, Web, and Desktop

Cross-Platform Development with Flutter Course Learn to build apps that work on Android, iOS, Web, and Desktop Go To Course Flutter is Google’s UI too

Mohamed Ibrahim 11 Oct 24, 2022
Example repository of handling permissions in Flutter using BLoC and Clean Architecture.

flutter_permission_handling A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get

Jop Middelkamp 0 Dec 28, 2021