Flutter Web : How to run javascript using dart js

淺唱寂寞╮ 提交于 2021-02-19 06:29:05

问题


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).

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>

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 docs: https://stripe.com/docs/js

Thank you


回答1:


You need to wrap that in a global variable

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

certify that app.js is loaded with defer

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

And inside flutter do

import 'dart:js' as js;

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

Source




回答2:


This isn't a Stripe-specific question, so I'd suggest looking into how you use a standard JS library with Flutter, i.e. Use JS library in Flutter



来源:https://stackoverflow.com/questions/59591330/flutter-web-how-to-run-javascript-using-dart-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!