isConnected method
isConnected is the future that returns a ConnectionState
object.
It can be either true or false.
Implementation
Future<ConnectionState> isConnected() async {
try {
final lookupResult = await InternetAddress.lookup(serverUrl);
if (lookupResult.isNotEmpty && lookupResult[0].rawAddress.isNotEmpty) {
_setCurrentState(ConnectionState(isConnected: true));
}
} catch (error, stacktrace) {
if (showErrorInDebugMode) {
if (kDebugMode) {
print(error);
print(stacktrace);
}
_setCurrentState(ConnectionState(isConnected: false));
}
}
return _previousState!;
}