isConnectedNetwork static method

Future<bool> isConnectedNetwork()

Implementation

static Future<bool> isConnectedNetwork() async {
  try {
    final result = await InternetAddress.lookup('google.com');
    if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
      if (kDebugMode) {
        print("Internet available");
      }
      return true;
    } else {
      if (kDebugMode) {
        print("Internet not available");
      }
      return false;
    }
  } on SocketException catch (_) {
    if (kDebugMode) {
      print("Something went wrong with connection");
    }
    return false;
  }
}