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

SocketException with flutter 3.13.x #12

Closed
tksoh opened this issue Aug 26, 2023 · 7 comments
Closed

SocketException with flutter 3.13.x #12

tksoh opened this issue Aug 26, 2023 · 7 comments

Comments

@tksoh
Copy link

tksoh commented Aug 26, 2023

In my Android project using plugin v2.0.0, this error came up when debugging the app on VSCode (v1.18.1), with Flutter 3.13.0 & 3.13.1, when internet is offline.

Exception has occurred.
SocketException (SocketException: Failed host lookup: 'icanhazip.com' (OS Error: The requested name is valid, but no data of the requested type was found.
, errno = 11004))

Output of flutter doctor:

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.13.1, on Microsoft Windows [Version 10.0.22621.2134], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.16)
[√] Android Studio (version 2021.2)
[√] VS Code, 64-bit edition (version 1.81.1)
[√] Connected device (4 available)
[√] Network resources
• No issues found!

No issue with Flutter 3.10.5.

Please advice. Thanks.

@OutdatedGuy
Copy link
Owner

Is this the same as #11 ?

@tksoh
Copy link
Author

tksoh commented Aug 27, 2023

@OutdatedGuy I'm not sure. #11 does not mention the flutter version used, and the exception type is different. In my case, the error is triggered by simply accessing InternetConnection().hasInternetAccess in the basic project created by 'flutter create'.

BTW, I just notice the error also happened when using plugin v1.0.0, maybe it has something to do on what the plugin is depending on.

One thing is that, the error is only caught if the "Uncaught Exception" is enabled in VSCode, else the app seems to run fine.

Another thing I don't understand is that wrapping the access to InternetConnection().hasInternetAccess in try-catch does nothing. Maybe there's some aspect of Dart I don't fully understand.

@OutdatedGuy
Copy link
Owner

@tksoh, Some issue with Flutter 3.13 I presume. Cuz after testing the issue on my side, the exception seems to be thrown in the http package.

But I have already wrapped that code in try-catch block.

try {
final response = await http.head(option.uri).timeout(option.timeout);
return InternetCheckResult(
option: option,
isSuccess: response.statusCode == 200,
);
} catch (_) {
return InternetCheckResult(
option: option,
isSuccess: false,
);
}

So I downgraded the http package to 1.0.0 and even 0.13.6 but still the issue persists.

Can you confirm if the issue is not happening prior to flutter version 3.13?

@OutdatedGuy
Copy link
Owner

Looks like the issue is with the latest Dart SDK that comes with Flutter 3.13: dart-lang/sdk#53334

@tksoh
Copy link
Author

tksoh commented Aug 28, 2023

Glad to know. Hopefully they can cut a new Dart soon on this.

@tksoh
Copy link
Author

tksoh commented Sep 13, 2023

Ah... I deleted my earlier reply. Looks like I mixed up on the Dart version in Flutter 3.13.3. My bad.

@tksoh
Copy link
Author

tksoh commented Sep 14, 2023

Flutter 3.13.4 with Dart 3.1.2 fixed the issue.

@tksoh tksoh closed this as completed Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants