【发布时间】:2021-07-21 15:45:26
【问题描述】:
我在 Flutter 中有以下代码来检查 Internet 连接。它以前可以与 Flutter 1 一起使用,但现在不能与 Flutter 2 一起使用。它表明无论我是否在线,Android 模拟器都已连接到互联网。将不胜感激有人指出我正确的方向。我还尝试了Connectivity Flutter Package,结果相同。
import 'dart:io';
...
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
}
} on SocketException catch (_) {
print('not connected');
}
【问题讨论】: