Created
September 20, 2023 19:06
-
-
Save rafaelqueiroz88/5209a1e1bced67029e35abe64ff4d392 to your computer and use it in GitHub Desktop.
Flutter test internet connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void testConnection() async { | |
try { | |
final connection = await InternetAddress.lookup('www.google.com'); | |
if (connection.isNotEmpty && connection.first.rawAddress.isNotEmpty) { | |
hasConnection = true; | |
} | |
} on SocketException catch (_) { | |
hasConnection = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment