How to go back from web view in flutter?

2,496

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

Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => _contentSearch(context),
      );
Share:
2,496
Falak
Author by

Falak

Updated on December 08, 2022

Comments

  • Falak
    Falak over 1 year

    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.