Skip to content

Instantly share code, notes, and snippets.

@vijayinyoutube
Created July 21, 2022 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayinyoutube/7f328446bc3b161cc848c2c9332d32fc to your computer and use it in GitHub Desktop.
Save vijayinyoutube/7f328446bc3b161cc848c2c9332d32fc to your computer and use it in GitHub Desktop.
late StreamSubscription subscription;
bool isDeviceConnected = false;
bool isAlertSet = false;
@override
void initState() {
getConnectivity();
super.initState();
}
getConnectivity() =>
subscription = Connectivity().onConnectivityChanged.listen(
(ConnectivityResult result) async {
isDeviceConnected = await InternetConnectionChecker().hasConnection;
if (!isDeviceConnected && isAlertSet == false) {
showDialogBox();
setState(() => isAlertSet = true);
}
},
);
@override
void dispose() {
subscription.cancel();
super.dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment