I am developing a flutter application where I need to check internet connection. But it is working fine for rest of the device except Samsung s23, Galaxy Z Fold5. I am checking the release apk, and do not have any real device access for this I could get any debug result.
In AndroidManifest, I have taken this permission:
<uses-permission android:name="android.permission.INTERNET" />
Here is the code, for checking for an internet connection:
final result = await InternetAddress.lookup('example.com');
try {
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
Get.snackbar('Internet', 'Navigate to Internet');
} else {
Get.snackbar('No Internet', 'Navigate to No Internet');
}
} on SocketException catch (_) {
Get.snackbar('No Internet', 'SocketException');
}
In release mode, it always shows the snackbar from the exception. I need to show the ‘Navigate to Internet’ snackbar.
Can I get any solution?
2
Answers
It seems like you are encountering an issue with checking the internet connection in your Flutter application specifically on Samsung S23 and Galaxy Z Fold5 devices when using the release APK. Here are a few suggestions to help you troubleshoot and potentially resolve the issue:
Network Security Configuration:
Network Permission:
Network Connectivity Check:
InternetAddress.lookup
method, try using theConnectivity
package in Flutter to check the network connectivity status. This package provides more comprehensive network connectivity checks and can handle various scenarios more effectively.Network Configuration:
Test on Real Devices:
Error Logging:
Please note that without access to the real devices for debugging, it may be challenging to pinpoint the exact cause of the issue. If possible, consider reaching out to users who have the Samsung S23 and Galaxy Z Fold5 devices to gather more information about their experience with the release APK.
By considering these suggestions and potentially testing on real devices, you may be able to identify the specific factors contributing to the issue and find a solution to ensure accurate internet connectivity checks on the Samsung S23 and Galaxy Z Fold5 devices.
It seems there is an issue in the Dart SDK for it. It was closed without a fix.
One suggestion there is to use the internet_connection_checker_plus package, which seems to do exactly what you’re trying to achieve.
To use it, add the following to your
pubspec.yaml
:And change your code to use it: