Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to go back from web view in flutter?

After clicking the button it should show the web view. I did this. But when press the back button it is closing the app. It does not go back to previous state. If I press back button it should go back to previous page or state. I am getting web view from a function. Here is my code:

_contentSearch(BuildContext context){
   url = "https://www.google.com";
   return WebviewScaffold(
      url: url,
      appBar: AppBar(
        title: Text("Google"),
      ),
      withJavascript: true,
      withLocalStorage: true,
      withZoom: false,
      enableAppScheme: true,
    )
  },
 );
}

And I am calling this method like this:

 FlatButton(
        padding: EdgeInsets.all(0.0),
        onPressed: (){
          Navigator.pushReplacement(
              context,
              new MaterialPageRoute(builder: (BuildContext context) => _contentSearch(context)
              ));
        },
       child: new Text("Button"),
    ),

It's not going back. It's always closing the app.

like image 323
Falak Avatar asked Nov 17 '25 06:11

Falak


1 Answers

Its because you are using pushReplacement(Replace the current route of the navigator) instead of push

Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => _contentSearch(context),
      );
like image 89
a0x2 Avatar answered Nov 19 '25 20:11

a0x2