我安装了flutter_webview_plugin。如果没有互联网连接,我正在尝试启动自定义静态 html 页面而不是我的 URL(我的网站 'wwww.duevents.in'),因为“网页不可用”页面看起来不是很专业。
我正在使用它来检查设备上的互联网并且它工作正常(当互联网连接时,'connectionStatus ==true',反之亦然):
Future check() async {
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
connectionStatus = true;
print("connected $connectionStatus");
}
} on SocketException catch (_) {
connectionStatus = false;
print("not connected $connectionStatus");
}
}
如果没有互联网连接,这是我有备用 URL 加载的代码:
WebviewScaffold(
url: connectionStatus == true ?"http://www.duevents.in" : Uri.dataFromString('<html><body>hello world</body></html>', mimeType: 'text/html').toString())
不管设备是否有互联网连接,它总是以某种方式向我显示带有此代码的 HTML 页面。请告诉我这里有什么问题。