How to show "You're offline" when web view app open without internet in Flutter Web view App?

Viewed 597

I create a WebView app in Flutter. here is the code

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

But when the App open without the internet it's showing this

enter image description here

I want to show here another image when opening this app without the internet. like this

enter image description here

How do I do this?

2 Answers

You can use this Package For checking Internet connection is available or not.

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
        }
      ) );

checking the internet in flutter is only available when you are on android or ios , it's like this because when you open your web application and it comes up it means you have a connection and if it doesn't you don't have a connection so c checking internet is meaningless

Related