checkInternetConnection function
void
checkInternetConnection({
- required dynamic callback(),
Checks the internet connection by attempting to resolve 'www.google.com'.
If the lookup succeeds, calls the callback
and logs success.
If it fails, shows an error message and retries by recursively calling itself.
callback
: Function to execute when the connection is successful.
Note: This method retries indefinitely on failure. Consider adding retry limits or delays to avoid potential infinite recursion.
Implementation
void checkInternetConnection({required Function() callback}) {
InternetAddress.lookup('www.google.com')
.then((onValue) {
callback();
logFile(
message: "connection with success",
name: "checkInternetConnection",
);
})
.catchError((handleError) {
ShowMessage.error(
message: handleError,
callback: () {
logFile(
message: "connection with error",
name: "checkInternetConnection",
);
checkInternetConnection(callback: callback);
},
);
});
}