Flutter Web:如何使用Dart JS运行JavaScript [英] Flutter Web : How to run javascript using dart js

查看:55
本文介绍了Flutter Web:如何使用Dart JS运行JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Web flutter上使用Stripe库.但不幸的是,到目前为止,仍然没有可用于Web抖动的条带库.因此,我尝试在网络抖动上运行javascript,它将在其中调用stripe-js库( https://stripe.com/docs/js/payment_intents/confirm_card_payment ).

I want to use the Stripe library on the web flutter. But unfortunately, until now there is still no stripe library available for web flutter. Therefore I try to run javascript on the web flutter, where it will call the stripe-js library (https://stripe.com/docs/js/payment_intents/confirm_card_payment).

首先,我想问的是如何在网络抖动中使用javascript库?像这样:

What I want to ask, first, is how to use the javascript library on web flutter? like this :

< script src ="https://js.stripe.com/v3/"></script>

其次,如何在网络颤动中调用javascript函数?像这样:

Secondly, how do I call the javascript function on the web flutter? like this :

stripe
   .confirmCardPayment ('{PAYMENT_INTENT_CLIENT_SECRET}', {
     payment_method: {
       card: cardElement,
       billing_details: {
         name: 'Jenny Rosen',
       },
     },
   })
   .then (function (result) {
     // Handle result.error or result.paymentIntent
   });

stripe-js文档: https://stripe.com/docs/js

stripe-js docs: https://stripe.com/docs/js

谢谢

推荐答案

您需要将其包装在全局变量中

You need to wrap that in a global variable

window.doStripePayment = (name) => {
    // Your code
}

确认 app.js 已加载 defer

<head>
    <script src="app.js" defer></script>
</head>

内部颤动

import 'dart:js' as js;

js.context.callMethod('doStripePayment', ['John Doe']);

来源

这篇关于Flutter Web:如何使用Dart JS运行JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆