最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Calling a javascript function from flutter app - Stack Overflow

programmeradmin3浏览0评论

I have a script given me by third party API that I should perform on the client side. For that I need to somehow call this JS function from dart. I've seen that there's a JS Library out in the pub, but I don't know exactly what I should do. Can somebody explain please?

I have a script given me by third party API that I should perform on the client side. For that I need to somehow call this JS function from dart. I've seen that there's a JS Library out in the pub, but I don't know exactly what I should do. Can somebody explain please?

Share Improve this question asked Nov 5, 2019 at 0:41 Zhangir SiranovZhangir Siranov 4791 gold badge5 silver badges15 bronze badges 1
  • 1 show to us Code – DevAS Commented Nov 5, 2019 at 0:54
Add a ment  | 

1 Answer 1

Reset to default 10

Here is a very good tutorial on how to use javascript libraries in Dart:

https://dev.to/graphicbeacon/how-to-use-javascript-libraries-in-your-dart-applications--4mc6

It uses the js package and gives a very easy solution.

In my case, I needed to call a js method from a Flutter app embedded on a webpage. The js method was on the main html page on which the Flutter app was embedded.

In this case, you need to use the parent selector to target the js method: @JS('parent.jsFunction')

@JS()
library main;

import 'package:js/js.dart';

@JS('parent.jsFunction')
external void jsFunction(dynamic mand, dynamic arg);

void callJsFunction() {
  jsFunction('mand', 'args');
}
发布评论

评论列表(0)

  1. 暂无评论