isConnectedToNetwork static method

Future<bool> isConnectedToNetwork()

Checks if the device is connected to a network. Returns true if connected to WiFi, mobile data, or ethernet.

Implementation

static Future<bool> isConnectedToNetwork() async {
  try {
    final connectivityResult = await Connectivity().checkConnectivity();
    return connectivityResult.any((result) =>
        result == ConnectivityResult.wifi ||
        result == ConnectivityResult.mobile ||
        result == ConnectivityResult.ethernet);
  } catch (e) {
    CometChatCallsLogger.error(
        "$_tag: Error checking network connectivity: $e");
    return false;
  }
}