首页 > 解决方案 > 如何在颤动中从网页视图返回?

问题描述

单击按钮后,它应该显示 Web 视图。我这样做了。但是当按下后退按钮时,它正在关闭应用程序。它不会回到以前的状态。如果我按下后退按钮,它应该返回上一页或状态。我正在从一个函数中获取 web 视图。这是我的代码:

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

我这样调用这个方法:

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

它不会回去了。它总是关闭应用程序。

标签: androidwebviewdartflutter

解决方案


这是因为您使用的是pushReplacement(替换导航器的当前路线)而不是push

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

推荐阅读