checkConnectivity method

Future<bool> checkConnectivity()

Instantly check whether the app has connection to the internet or not. Return true if the device is connected to the internet. Otherwise false.

Implementation

Future<bool> checkConnectivity() async {
  try {
    final result = await InternetAddress.lookup(domain);
    if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
      return true;
    }
    return false;
  } on SocketException catch (_) {
    return false;
  }
}