【问题标题】:Flutter horizontal swipe gesture in webview在 webview 中颤动水平滑动手势
【发布时间】:2021-12-13 11:59:58
【问题描述】:

我现在正在构建一个 Flutter 应用程序,它有一个登录信息,它会路由到一个新屏幕,其中包含一个脚手架,其中包含一个 webView 作为主体。对于我使用的导航

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

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

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

非常感谢!

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    好的,所以诀窍是用 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;
                     },
    .....
    

    【讨论】:

      猜你喜欢
      • 2018-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多