setupConnectivityListner method

dynamic setupConnectivityListner({
  1. CustomNoInternetWrapper? offlineWidget,
  2. NoConnectivityStyle? connectivityStyle = NoConnectivityStyle.SNACKBAR,
  3. Widget? noInternetText,
})

Implementation

setupConnectivityListner(
    {CustomNoInternetWrapper? offlineWidget,
    NoConnectivityStyle? connectivityStyle = NoConnectivityStyle.SNACKBAR,
    Widget? noInternetText}) async {
  _userWidget = offlineWidget;
  _connectivityStyle = connectivityStyle;
  customNoInternetText = noInternetText;
  if (_connectivityStyle == NoConnectivityStyle.CUSTOM &&
      _userWidget == null) {
    throw ("widgetForNoInternet is missing");
  }

  checker.onStatusChange.listen((status) {
    if (_connectivityStyle == NoConnectivityStyle.CUSTOM &&
        (contextKey.currentState?.overlay) != null) {
      _overlayState = (contextKey.currentState!.overlay);
    }

    switch (status) {
      /// ConnectedState
      case InternetConnectionStatus.connected:
        try {
          _removeNoInternet();
        } catch (e) {}
        print('You are Connected to the internet.');
        break;

      /// DisconnectedState
      case InternetConnectionStatus.disconnected:
        showNoInternet();
        print('You are disconnected from the internet.');
        break;
    }
  });
}