我正在使用包(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)。
Может быть,вам поможет:https://github.com/flutter/flutter/issues/108801 问题可能出在初始的 NavigationDelegate 上。