简体   繁体   中英

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.

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

Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => _contentSearch(context),
      );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM