【问题标题】:Flutter: willpopscope not working while InAppWebview : Need Swipe back to Navigate Back in IOS ( Flutter InAppWebView)Flutter:在 InAppWebview 时 willpopscope 不工作:需要在 IOS 中滑动以返回导航(Flutter InAppWebView)
【发布时间】:2022-10-21 12:39:35
【问题描述】:

我已经使用了这段代码,它将在 Android 中完美运行,但我在 IOS 中需要这个东西

WillPopScope(onWillPop: () => Future.value(false), child: _main(context));

另外,我查看了以下链接:

1) Stackoverflow disable swipe back

2) Github InappWebview swipe back issue from the package itself

我的问题是相反的: 如何防止回扫

-> 如果您观察到 inAppWebview 它将停止工作,仅在第一页向后滑动,但所有其他(内页)将完美运行我想停止向后滑动所有页面而不使用手势检测

那么有没有办法做到这一点?

【问题讨论】:

  • 我已经尝试过那个,但如果子小部件是 InAppWebview,它就不起作用。
  • @amit.flutter 你能解决这个问题吗?使我抓狂。
  • @scoots 我研究了很多,但这两件事不可能一起完成,所以我只是在右上角的应用栏中添加了网页后退和前进按钮(如 google crome 按钮)和左侧主 BACK 按钮以关闭 webview 并导航回主页或上一个按钮

标签: ios flutter flutter-inappwebview


【解决方案1】:

我尝试了很多,但无法滑动,我们可以在 IOS 中从头开始覆盖整个方法,或者一个简单的解决方案是我们可以在应用程序的应用栏中添加前进和后退按钮

1)解决方案1(为网页添加前进和后退按钮以及关闭WEBVIEW页面的主后退按钮)

  1. 解决方案 2(覆盖 IOS 方法)
class CustomMaterialPageRoute extends MaterialPageRoute {
@protected
  bool get hasScopedWillPopCallback {
    return false;
  }
  CustomMaterialPageRoute({
    @required WidgetBuilder builder,
    RouteSettings settings,
    bool maintainState = true,
    bool fullscreenDialog = false,
  }) : super(
          builder: builder,
          settings: settings,
          maintainState: maintainState,
          fullscreenDialog: fullscreenDialog,
        );
}

结帐在这里填写答案:https://github.com/flutter/flutter/issues/14203#issuecomment-540663717

另一个有用的链接:1)https://pub.dev/packages/cupertino_will_pop_scope 2)https://github.com/flutter/flutter/issues/14203#issuecomment-1172824709 3)https://github.com/flutter/flutter/issues/14203#issuecomment-1193809403

【讨论】:

    猜你喜欢
    • 2021-04-09
    • 2021-10-20
    • 2021-07-24
    • 2021-08-07
    • 1970-01-01
    • 2021-10-13
    • 2021-06-19
    • 1970-01-01
    • 2022-11-30
    相关资源
    最近更新 更多