简体   繁体   English

如何在颤抖中从Web视图返回?

[英]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. 我正在从功能获取Web视图。 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 这是因为您使用的是pushReplacement (替换导航器的当前路径)而不是push

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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