initConnectivity method

Future<void> initConnectivity({
  1. VoidCallback? onOnline,
  2. VoidCallback? onOffline,
})

Initializes connectivity and sets up listeners for changes

Implementation

Future<void> initConnectivity({
  VoidCallback? onOnline,
  VoidCallback? onOffline,
}) async {
  // Check current connectivity status
  List<ConnectivityResult> result = await Connectivity().checkConnectivity();
  _isInternetConnected(result);

  // Listen for changes in connectivity
  Connectivity()
      .onConnectivityChanged
      .listen((List<ConnectivityResult>? result) {
    if (kDebugMode) {
      print(result);
    }

    _isInternetConnected(result);
  });
}