[英]Flutter horizontal swipe gesture in 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;
},
.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.