'Flutter connectivity: Works on Android, but on iOS simulator when I can open webpages in Safari I have internet but the app says there is no internet?

I use this package: https://pub.dev/packages/connectivity_plus

I have a finished application that is working on Android but when I am testing it on iOS it shows that there is no internet. I can use and open pages in Safari so there is definitely one. But the following code returns false in iOS:

class InternetConnectivity with ChangeNotifier {
  StreamSubscription<ConnectivityResult>? _subscription;
  bool haveInternet = false;

  void checkConnectivity() {
    if (_subscription == null) {
      _subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
        bool res = result == ConnectivityResult.mobile || result == ConnectivityResult.wifi;
        setHaveInternet = res;
      });
    }
  }

  set setHaveInternet(bool value) {
    if (haveInternet != value) {
      haveInternet = value;
      notifyListeners();
    }
  }
}

I don't get any errors so I don't really know where to look for the problem.

On the screen where it checks that internet connection starts with this:

bool _haveInternet = true;

then in initState() I set the value of it:

  @override
  void initState() {
    super.initState();
    
    InternetConnectivity ? _internetConnectivity = InternetConnectivity();

    setState(() {
      _haveInternet = _internetConnectivity!.haveInternet;
    });

After the initState() ran, the _haveInternet becomes false, so the connectivity_plus package returns false while normally it should be true.

Thanks in advance.



Solution 1:[1]

The package has a bug. According to documentation it should only affect iOS simulator. https://github.com/fluttercommunity/plus_plugins/issues/479

From package comments:

  /// On iOS, the connectivity status might not update when WiFi
  /// status changes, this is a known issue that only affects simulators.
  /// For details see https://github.com/fluttercommunity/plus_plugins/issues/479.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marius Lastauskas