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?
1 Answer
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 command, dynamic arg);
void callJsFunction() {
jsFunction('command', 'args');
}