hasInternetAccess property
Checks if there is internet access by verifying connectivity to the specified Uris.
Returns a Future that completes with a boolean value indicating whether internet access is available or not.
Implementation
Future<bool> get hasInternetAccess async {
final completer = Completer<bool>();
int remainingChecks = _internetCheckOptions.length;
int successCount = 0;
for (final option in _internetCheckOptions) {
unawaited(
_checkReachabilityFor(option).then((result) {
if (result.isSuccess) {
successCount += 1;
}
remainingChecks -= 1;
if (completer.isCompleted) return;
if (!enableStrictCheck && result.isSuccess) {
// Return true immediately if not in strict mode and a success is found.
completer.complete(true);
} else if (enableStrictCheck && remainingChecks == 0) {
// In strict mode, complete only when all checks are done.
completer.complete(successCount == _internetCheckOptions.length);
} else if (!enableStrictCheck && remainingChecks == 0) {
// In non-strict mode, complete as false if no success is found.
completer.complete(false);
}
}),
);
}
return completer.future;
}