checkConnectivity static method

Future<ConnectivityResult> checkConnectivity({
  1. VoidCallback? onConnected,
  2. VoidCallback? onDisconnected,
})

Check the connection status.

You can specify the callback when connected with onConnected and when disconnected with onDisconnected.

Implementation

static Future<ConnectivityResult> checkConnectivity({
  VoidCallback? onConnected,
  VoidCallback? onDisconnected,
}) async {
  final result = await Connectivity().checkConnectivity();
  if (result == ConnectivityResult.none) {
    onDisconnected?.call();
  } else {
    onConnected?.call();
  }
  return result;
}