以下是无关的上述任务,但最终结果是相同的.我有连接插件和IOS配置并发症.所以我使用以下方法来检查我的应用程序是否连接到互联网: static Future checkInternetConnectivity() async {
bool isConnected;
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
isConnected = true;
}
} on SocketException catch (_) {
isConnected = false;
}
return isConnected;
}AppUtil.checkInternetConnectivity().then((isOnline) async {
if (isOnline) {...} else {...}
})我从来没有看到谷歌网站宕机。如果我想听互联网连接,我使用计时器。如果你想检查移动的数据连接或WiFi数据连接,对不起!你仍然必须继续实现连接。
|