Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[connectivity_plus] "onConnectivityChanged" having troubles on receiving results #479

Closed
theiskaa opened this issue Oct 1, 2021 · 14 comments
Labels
bug Something isn't working connectivity_plus Connectivity Plus Hacktoberfest Issues taking part in Hacktoberfest

Comments

@theiskaa
Copy link

theiskaa commented Oct 1, 2021

I have problems with listening to the connectivity state changing.

Steps to reproduce issue:

  • Open the app with wifi network
  • Then turn off wifi (Stream will receive the connectivity result)
  • And then turn on the wifi app won't receive the connectivity result again.

And I tried just printing the results. But also it wasn't receive the connectivity results.

Screen.Recording.2021-10-01.at.22.51.51.mov
@theiskaa theiskaa added the bug Something isn't working label Oct 1, 2021
@mhadaily mhadaily added Hacktoberfest Issues taking part in Hacktoberfest connectivity_plus Connectivity Plus labels Oct 1, 2021
@loud-at-heart
Copy link

@theiskaa can I take up this task

@theiskaa
Copy link
Author

theiskaa commented Oct 2, 2021

@loud-at-heart Sure thing.

@ralphvmo
Copy link

ralphvmo commented Oct 3, 2021

Sometime it happens. But the problem that I face is that when I turn on the wifi then the connectivity result is none and vice versa when I turn off the wifi, the connectivity result is wifi. Does that library work like this or this is a bug ?

@LukaGiorgadze
Copy link

@theiskaa I think it would be nice if you post the code so everyone can reproduce this bug.

@theiskaa
Copy link
Author

theiskaa commented Oct 3, 2021

Here it is:

Code
class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool isConnected = true;

  late StreamSubscription connectivityStream;

  void setConnectivitySubscription() {
    connectivityStream = Connectivity().onConnectivityChanged.listen(
      (ConnectivityResult result) {
        setState(() {
          isConnected = (result != ConnectivityResult.none);
        });
      },
    );
  }

  @override
  void initState() {
    super.initState();
    setConnectivitySubscription();
  }

  @override
  void dispose() {
    connectivityStream.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Text(
          isConnected ? 'Connected' : 'No connection',
          style: Theme.of(context).textTheme.headline4,
        ),
      ),
    );
  }
}

@alexbatalov
Copy link
Contributor

This is a pretty old bug that only affects simulator. See ashleymills/Reachability.swift#151. I have tested both Reachability.swift and NWPathMonitor and they both report changes in host Wi-Fi incorrectly. Both work fine on physical devices. Guess we should note that in docs.

@LukaGiorgadze
Copy link

This is a pretty old bug that only affects simulator. See ashleymills/Reachability.swift#151. I have tested both Reachability.swift and NWPathMonitor and they both report changes in host Wi-Fi incorrectly. Both work fine on physical devices. Guess we should note that in docs.

Absolutely agree, this should be noted in docs to avoid such confusions.

@miquelbeltran
Copy link
Member

Documentation has been updated. Do we need to keep this ticket open?

@LukaGiorgadze
Copy link

Thanks @miquelbeltran , i think we can close an issue.

@faisalmushtaq007
Copy link

I am having same issue, i test app on ios simulator and it shows ConnectivityResult.none even though my wifi is connected.
Please i need a solution for this

@Sun3
Copy link

Sun3 commented Aug 15, 2023

Any updates? This issue is still happening.

Thanks.

@mad-mikey
Copy link

Hi everyone,
I have a similar trouble on physical device (iPhone 7 iOS 15.7.7): even if the iPhone is online and so I expect ConnectivityResult.wifi, I get ConnectivityResult.none

A bad thing for our customers.

Any news about it?

Thank you

@yassine-bennkhay
Copy link

yassine-bennkhay commented Mar 12, 2024

I am still getting the same issue, Has anyone found a solution?

@mad-mikey
Copy link

Temporary fix
#198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working connectivity_plus Connectivity Plus Hacktoberfest Issues taking part in Hacktoberfest
Projects
None yet
Development

No branches or pull requests