hasNetwork function

Future<bool> hasNetwork()

Whether there is network connectivity.

Implementation

Future<bool> hasNetwork() async {
  try {
    final result = await InternetAddress.lookup('example.com');

    return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
  } on SocketException {
    developer.log(
      'Failed to connect to the internet.',
      name: 'keycloak_wrapper',
    );
    return false;
  }
}