hasConnection method
Implementation
Future<bool> hasConnection() async {
final connectivityResult = await (Connectivity().checkConnectivity());
final hasNetwork = [
ConnectivityResult.mobile,
ConnectivityResult.wifi,
ConnectivityResult.ethernet,
].contains(connectivityResult);
final isVpn =
connectivityResult == ConnectivityResult.vpn || await isVpnActive();
final connected = hasNetwork
? kIsWeb
? await doesConnectTo('/favicon.ico') ||
await doesConnectTo('/favicon.png') ||
await doesConnectTo('/favicon.gif')
: await doesConnectTo('google.com') ||
await doesConnectTo('www.baidu.com')
: isVpn;
if (connected != _wasConnected) {
_wasConnected = connected;
controller.add(connected);
}
return connected;
}