无法使用 flutter WebViewWidget 进行导航

问题描述 投票:0回答:1

我正在使用包(webview_flutter)[https://pub.dev/packages/webview_flutter]来显示网络视图。我想在用户被定向到特定网址时触发某个功能,但我总是收到此错误:

W/cr_AwContentsClient( 4446): Denied starting an intent without a user gesture, URI https://checkout.stripe.dev/success

这是我的控制器初始化代码:

webController = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            log("onProgress $progress");
          },
          onPageStarted: (String url) {
            log("onPageStarted $url");
          },
          onPageFinished: (String url) {
            log("onPageFinished $url");
          },
          onWebResourceError: (WebResourceError error) {
            log("onWebResourceError $error");
          },
          onNavigationRequest: (NavigationRequest request) {
            inspect(request);
            if (request.url.startsWith(successUrl)) {
              status.value = CheckoutStatus.successful;
              return NavigationDecision.prevent;
            } else if (request.url.startsWith(canceledUrl)) {
              status.value = CheckoutStatus.canceled;
              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse(url));

    if (webController.platform is AndroidWebViewController) {
      AndroidWebViewController.enableDebugging(true);
      (webController.platform as AndroidWebViewController)
          .setMediaPlaybackRequiresUserGesture(false);
    }

我不关心重定向本身是否有效,我只想读取 url(这显然以某种方式工作,因为错误消息显示了我想要读取的正确 url)。

android ios flutter webview stripe-payments
1个回答
0
投票

Может быть,вам поможет:https://github.com/flutter/flutter/issues/108801 问题可能出在初始的 NavigationDelegate 上。

© www.soinside.com 2019 - 2024. All rights reserved.