在Flutter Web view App中,当Web view App在没有互联网的情况下打开时,如何显示“您已离线”?[closed]

mzillmmw  于 2022-11-17  发布在  Flutter
关注(0)|答案(2)|浏览(232)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
10个月前就关门了。
这篇文章是昨天编辑并提交审查的。
Improve this question
我正在flutter中制作一个webview应用程序,下面是webview的代码

WebView(
            initialUrl: 'https://deoxy.tech/',
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController webViewController) {
              _controllerCompleter.future.then((value) => _controller = value);
              _controllerCompleter.complete(webViewController);
            },
          ),

Web视图工作正常,但问题是当没有Internet连接时,应用程序会显示如下加载错误

我想显示另一个小部件或图像,而不是这个加载错误。像当没有互联网连接,我需要显示“没有互联网连接”屏幕/小部件这样。

我该怎么做?

nhaq1z21

nhaq1z211#

您可以使用this Package检查Internet连接是否可用。

bool result = await DataConnectionChecker().hasConnection;

 return Scaffold(
      body: WebView(
        if (result == true) {
        initialUrl: "https://google.com/",
        onWebViewCreated: (WebViewController webViewController){
          _controller.complete(webViewController);
        },}
        else{
          //i am not connected to any network
        }
      ) );
sqyvllje

sqyvllje2#

flutter中的互联网检查功能仅在您使用Android或iOS时可用,这是因为当您打开Web应用程序时,它会出现,这意味着您已连接,如果它没有出现,则表示您没有连接,因此检查互联网没有意义

相关问题