setupConnectivityListner method
dynamic
setupConnectivityListner({
- CustomNoInternetWrapper? offlineWidget,
- NoConnectivityStyle? connectivityStyle = NoConnectivityStyle.SNACKBAR,
- Widget? noInternetText,
Implementation
setupConnectivityListner(
{CustomNoInternetWrapper? offlineWidget,
GlobalKey<NavigatorState>? navigatorKey,
NoConnectivityStyle? connectivityStyle = NoConnectivityStyle.SNACKBAR,
Widget? noInternetText}) async {
if (navigatorKey != null) {
_contextKey = navigatorKey;
}
_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();
connectivityController.sink
.add(ConnectivityWatcherStatus.connected);
} catch (e) {
print(e);
}
break;
/// DisconnectedState
case InternetConnectionStatus.disconnected:
connectivityController.sink
.add(ConnectivityWatcherStatus.disconnected);
showNoInternet();
break;
}
});
}