isInternetAvailable top-level property

Future<bool> get isInternetAvailable

Convenience probe that pings google.com to check for internet access.

Returns false when:

  • the host cannot be resolved (no DNS),
  • resolution succeeds but the result is empty,
  • any SocketException is thrown during the lookup.

Implementation

Future<bool> get isInternetAvailable async {
  try {
    final List<InternetAddress> result =
        await InternetAddress.lookup('google.com');
    return result.isNotEmpty && result.first.rawAddress.isNotEmpty;
  } on SocketException {
    return false;
  }
}