Giter Site home page Giter Site logo

marchdev-tk / cross_connectivity Goto Github PK

View Code? Open in Web Editor NEW
30.0 1.0 14.0 2.6 MB

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.

License: BSD 3-Clause "New" or "Revised" License

Swift 1.88% Objective-C 0.04% Dart 28.88% HTML 1.18% C++ 37.98% C 3.37% Batchfile 2.65% Ruby 4.76% CMake 19.25%
dart dartlang dart2 flutter flutter-plugin flutter-package connectivity windows linux macos macosx ios android web internet-connectivity internet-connection internet-connection-checker

cross_connectivity's Introduction

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.

cross_connectivity's People

Contributors

cbenhagen avatar olehmarch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cross_connectivity's Issues

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.

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

ConnectivityStatus.unknown in Web

I installed the plugin and it is working wonderful under Android.
But when I try it in Flutter Web, it is returning connection unknown...

Potential stack overflow

looking at your code before switching to your plugin I stumbled upon this function:

grafik

for my understanding it will recursively call itself after the delay without any end. Actually why call recursively at all and not use a loop or a Stream.periodic?

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

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

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.

有网时没有试试获取到

我在使用window desktop开发,我在window下打开电脑网路,为什么没有即使获取到网路,要等1分钟左右才会有?没有断开网路是时时的,打开网路没有时时。我怎么解决这个问题?

Turning WiFi off does not change isConnected

Issue:
When listening to isConnected and turning wifi off the connection status does not change, only if I put my computer in airplane mode will this stream update, however when turning off airplane mode the connection will not come back until I also turn wifi back on.

Tested on:
Flutter 3.7.6 & 3.7.7 • channel stable
Windows 11 Desktop
Chrome Web Version 110.0.5481.178 (Official Build) (64-bit)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.