hasInternetConnection static method

Future<bool> hasInternetConnection()

Checks if the device has an active internet connection.

Implementation

static Future<bool> hasInternetConnection() async {
  try {
    final result = await InternetAddress.lookup('example.com');
    return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
  } on SocketException catch (_) {
    return false;
  }
}