Created
July 21, 2022 18:32
-
-
Save vijayinyoutube/7f328446bc3b161cc848c2c9332d32fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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