-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Bug]: Issue with onConnectivityChanged listener on iOS: ConnectivityResult.none followed by ConnectivityResult.wifi even when connected to Wifi #3453
Comments
It isn't clear to me if you are running the app as installed from your device, or from the
So if you are performing a hot-restart, it could be that iOS's |
Hello, I am experiencing the same issue, whether running the app from an isolated bundle or using The first call to check the connection returns [ConnectivityResult.none], When using the listener, I sequentially receive both states (none, wifi). It appears that the two states are emitted in quick succession. Even though this might be an OS-level call, it could be due to native events being emitted incorrectly or an issue specific to iOS 18. Are there any references or an estimated timeline for a resolution? |
This is a community project run by volunteers, don't expect anyone from the team working on this. If anyone from the community finds out and submits a solution, then I am happy to review the PR. |
I understand, sorry for my mistake what I write on section of 'how to reproduce'. thank you for your response. |
Temporary Workaround for Incorrect Network Status DetectionI have a temporary workaround for handling connectivity issues in Flutter. Initially, I used the _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
Future<void> _updateConnectionStatus(List<ConnectivityResult> result) async {
print("Connectivity Status: $result");
if (result.contains(ConnectivityResult.none)) {
// Example: Navigate to network error page
}
} However, this approach is not suitable for certain cases. Even when the network is actually connected, it might incorrectly display a network error to users. Improved Approach: Double-Checking ConnectivityA better approach is to use if (result.contains(ConnectivityResult.none)) {
List<ConnectivityResult> connectivityState = await _connectivity.checkConnectivity();
if (!connectivityState.contains(ConnectivityResult.none)) {
return;
}
// Proceed with network error handling
} By implementing this, we prevent users from being redirected to a network error page due to a temporary Next StepsI hope this solution helps you and other developers facing similar issues. Additionally, I will investigate the root cause and, if possible, submit a PR to address this problem at the source. Thanks! |
That makes sense to me. From a design point of view, I wouldn't rely on connectivity_plus to show an error message to the user, as it can show a Remember as well that having connectivity doesn't mean you are actually connected to the internet, but rather just that the OS is connected to some network. There are other plugins that track actual internet connection and those may be a better choice for this use case. |
Thanks for your workaround @0minKoh |
Platform
iOS 18
Plugin
connectivity_plus
Version
6.1.1
Flutter SDK
3.27.3
Steps to reproduce
Steps to reproduce:
_connectivity.onConnectivityChanged
listener.Observed behavior:
Even when connected to Wifi, the connection status changes are observed in the following order:
This issue sometimes occurs when navigating between screens using Navigator.of(context).pushAndRemoveUntil().
A similar issue was reported in #479, but that issue was described as only occurring in the simulator.
Code Sample
Logs
Flutter Doctor
Checklist before submitting a bug
flutter pub upgrade
flutter clean
The text was updated successfully, but these errors were encountered: