isConnected method

Future<bool> isConnected()

Checks if the device is connected to the internet by attempting to resolve 'google.com'.

Returns true if connected, otherwise false.

Implementation

Future<bool> isConnected() async {
  try {
    final result = await InternetAddress.lookup('google.com');
    return (result.isNotEmpty && result.first.rawAddress.isNotEmpty);
  } catch (e) {
    return false;
  }
}