Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查设备是否连接到 WiFi 或移动数据,我正在使用连接,但是当 WiFi 上没有活动的 Internet 连接时它会超时,如果没有活动连接但仍然连接到,我想启用一些功能任何 WiFi
希望能解开我的疑惑,谢谢
希望能帮到你
参考:https ://stackoverflow.com/a/49648870/5588637
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'); }