webview中的颤振水平滑动手势



我现在正在构建一个Flutter应用程序,它有一个登录,路由到一个新的屏幕,它包含一个支架,它持有一个webView作为一个体。对于导航,我使用

Navigator.pushNamed(
context,
webshopRoute,
arguments: WebshopArguments(initialUrl: shopUrl),
);

当我在webView中浏览时,我想要返回-在webView中-从右向左滑动手势(对于没有后退按钮的手机,如我的Pixel 4)。但是现在滑动的作用是它跳回登录屏幕。

我在这里找到的唯一的帖子是如何禁用它,这是我不想要的。

非常感谢!

好的,技巧是用WillPopScope包装脚手架,并在onWillPop内的控制器上调用goBack()。

late WebViewController _webViewController;
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
_webViewController.goBack();
return false;
},
child: Scaffold(
body: SafeArea(
child: WebView(javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
},
.....

最新更新