Flutter webview PayPal 输入错误?

Posted

技术标签:

【中文标题】Flutter webview PayPal 输入错误?【英文标题】:Flutter webview PayPal intergation error? 【发布时间】:2021-10-04 04:16:50 【问题描述】:

我想像这样集成 PayPal 按钮: https://developer.paypal.com/demo/checkout/#/pattern/client

我把这个示例代码放在一个 html 文件 (assets/paypal.html) 中,然后从资产中读取到 WebView:

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      body: WebView(
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) 
          _controller = webViewController;
          _loadHtml();
        ,
      ),
    );
  

  void _loadHtml() async 
    String fileText = await rootBundle.loadString('assets/paypal.html');
    _controller!.loadUrl(Uri.dataFromString(fileText, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  

但我收到此错误(未捕获的错误:按钮的引导错误):

[INFO:CONSOLE(2)] "insertPPTM [object Object]", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "Uncaught Error: Bootstrap Error for buttons:

Can not read window host

Error: Can not read window host
    at j (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:18528)
    at B (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:18625)
    at zt (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:58764)
    at Cu (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:288789)
    at Object.__get__ (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:288874)
    at o (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:291801)
    at https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:291984
    at Module.<anonymous> (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:292214)
    at t (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:157)
    at https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:941", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "Uncaught Error: Bootstrap Error for common:

Can not read window host

Error: Can not read window host
    at j (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:18528)
    at B (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:18625)
    at zt (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:58764)
    at Iu (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:289405)
    at Object.__get__ (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:289453)
    at o (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:291801)
    at https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:291984
    at Module.<anonymous> (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:292214)
    at t (https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:157)
    at https://www.paypal.com/sdk/js?client-id=test&currency=USD:2:941", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "unhandled_error [object Object]", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "unhandled_error [object Object]", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "Uncaught Error: Can not read window host", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2) [INFO:CONSOLE(2)] "Uncaught Error: Can not read window host", source: https://www.paypal.com/sdk/js?client-id=test&currency=USD (2)

我尝试了 2 个 Flutter WebView 插件,同样的错误(webview_flutter 2.0.10flutter_webview_plugin 0.4.0

【问题讨论】:

【参考方案1】:

无法从 web 视图中使用 PayPal,如 documentation explains。

不要使用 WebView 在您的 应用

您的应用程序不得使用 WebView 或类似的自定义浏览器 用于显示 PayPal 网页的机制。相反,使用适当的 用于管理 PayPal 体验或启动 PayPal 网络的 PayPal SDK 系统浏览器中的页面或批准的浏览器视图机制 例如 ios 上的 Safari 视图控制器或 Chrome 上的自定义选项卡 安卓。

【讨论】:

以上是关于Flutter webview PayPal 输入错误?的主要内容,如果未能解决你的问题,请参考以下文章

使用 Webview 的贝宝

如何在不使用 webview 或浏览器的情况下实现 paypal?

通过 webview 扑动贝宝

Flutter中 webview的键盘问题解决

Flutter WebView安卓端输入框不能长按粘贴

flutter_webview_plugin 加载全屏页面的简单使用