Skip to content

Instantly share code, notes, and snippets.

@rafaelqueiroz88
Created September 20, 2023 19:06
Show Gist options
  • Save rafaelqueiroz88/5209a1e1bced67029e35abe64ff4d392 to your computer and use it in GitHub Desktop.
Save rafaelqueiroz88/5209a1e1bced67029e35abe64ff4d392 to your computer and use it in GitHub Desktop.
Flutter test internet connection
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