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
1 Answer
Reset to default 10Here 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');
}