hasConnection property
gives True or False whether the device is Connected to Internet and Internet is available or not.
Implementation
Future<bool> get hasConnection async {
final Completer<bool> completer = Completer<bool>();
int length = _defaultCheckOptions.length;
if (!await isNetworkConnected()) {
return false;
}
for (final AddressCheckOption option in _defaultCheckOptions) {
unawaited(
_hasInternetConnection(option).then((bool result) {
length -= 1;
if (completer.isCompleted) return;
if (result) {
debugPrint(
"option checked : ${_defaultCheckOptions.length - length}");
completer.complete(true);
} else if (length == 0) {
completer.complete(false);
}
}),
);
}
return completer.future;
}