plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: Repeated Connectivity result - ConnectivityResult.mobile

Open raphire08 opened this issue 2 years ago • 2 comments

Platform

iOS 16

Plugin

Connectivity Plus

Version

3.0.2

Flutter SDK

3.7.12

Steps to reproduce

Whenever connectivity result change we are logging it

Connectivity _connectivity = Connectivity();
 _connectivity.onConnectivityChanged
        .listen((ConnectivityResult result) {
     log('Connectivity subscription result: $result');
});

For many users we are getting repeated ConnectivityResult.mobile. Wanted to know what could cause this? Ideally it should be ConnectivityResult.mobile -> ConnectivityResult.none -> ConnectivityResult.mobile.

 
Info: 9/5/2023 2:05:01 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:05:02 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:05:02 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:05:05 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:05:05 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:51 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:51 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:54 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:54 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:56 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:11:56 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:12:01 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:12:01 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:17 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:17 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:20 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:20 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:22 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:22 PM - Skipping connectivity change : ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:25 PM - Connectivity subscription result: ConnectivityResult.mobile
 
Info: 9/5/2023 2:32:25 PM - Skipping connectivity change : ConnectivityResult.mobile

Code Sample

Connectivity _connectivity = Connectivity();
 _connectivity.onConnectivityChanged
        .listen((ConnectivityResult result) {
     log('Connectivity subscription result: $result');
});

User cellular network and we get repeated ConnectivityResult.mobile.



### Logs

```shell
// not required

Flutter Doctor

[✓] Flutter (Channel stable, 3.7.12, on macOS 13.0.1 22A400 darwin-x64, locale en-IN)
    • Flutter version 3.7.12 on channel stable at /Volumes/Work/flutter_sdk/flutter_3.7.12
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (5 months ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/sumeet/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc4
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.13+0-b1751.21-8125866)

[✓] VS Code (version 1.80.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.68.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 116.0.5845.179
    ! Error: Failed to prepare the device for development. Please unlock and reconnect the device. (code 806)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Checklist before submitting a bug

  • [X] I Google'd a solution and I couldn't find it
  • [X] I searched on StackOverflow for a solution and I couldn't find it
  • [X] I read the README.md file of the plugin
  • [X] I'm using the latest version of the plugin
  • [X] All dependencies are up to date with flutter pub upgrade
  • [X] I did a flutter clean
  • [X] I tried running the example project

raphire08 avatar Sep 08 '23 06:09 raphire08

Me too. On IOS - when disable/enable WiFi, why do I get several messages (3 times when disable, 7 times when enable): flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.none flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.none flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.none

flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi flutter: ConnectivityManager: Connectivity subscription result: ConnectivityResult.wifi

burekas7 avatar Oct 29 '23 15:10 burekas7

Same for me. This started to occur with version 5.0.0

daniellampl avatar Nov 29 '23 17:11 daniellampl

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Feb 28 '24 00:02 github-actions[bot]

Anything on this ?

raphire08 avatar Feb 28 '24 03:02 raphire08

The callback is called whenever the OS NotificationCenter emits a value, and the package doesn't check if the value is distinct to the previous one, that would be something you would have to do on your side.

There is also a PR on the works that is changing the way the connectivity values are returned, it would be good if you could test it for your usecase: https://github.com/fluttercommunity/plus_plugins/pull/2599

miquelbeltran avatar Feb 28 '24 07:02 miquelbeltran

It is mentioned in the README already that currently plugin doesn't filter values returned by the underlying platform. Check the last sentence here: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/connectivity_plus/connectivity_plus#ios--macos

Closing as currently this is how the plugin works. We plan to update the behavior to distinct values, but it will happen a bit later.

vbuberen avatar Apr 08 '24 20:04 vbuberen