abner / flutter_js

A Javascript engine to use with flutter. It uses quickjs on Android and JavascriptCore on IOS
MIT License
464 stars 117 forks source link

Call a function with parameters #109

Closed ARASHz4 closed 1 year ago

ARASHz4 commented 1 year ago

How to call a function with parameters from dart to js?

PS-Developers commented 1 year ago

add.js function add(a, b) { return a + b; }

dart

final JavascriptRuntime runtime= getJavascriptRuntime(); int a =10; int b=20;

String addJS = await rootBundle.loadString("assets/add.js"); final add = runtime.evaluate("""$addJS\n add($a,$b);"""); debugPrint("add= ${add.stringResult}");