Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run javascript in flutter_inappwebview

I found it difficult when I want to run javascript in package flutter_inappwebview, Previously I tried with webview_flutter I was able to run runJavascript but there was a problem when I used webview_flutter I could not upload this file for example when I used webview_flutter

final json =
              jsonEncode(TawkVisitor(name: "jhon", email: "[email protected]"));

          String javascriptString;

          javascriptString =
              '''Tawk_API = Tawk_API || {};Tawk_API.onLoad = function() {Tawk_API.setAttributes($json);''';

          await controller.runJavascript(javascriptString);

          setState(() {});

can you guys help how to run javascript in packages flutter_inappwebview

like image 731
Irvan Thole Avatar asked Feb 05 '26 00:02

Irvan Thole


1 Answers

Try this one:

String yourCode = "alert('JS Running')";
controller.evaluateJavascript(source: yourCode).then((result) {
debugPrint(result);
});
like image 90
AmmarJavedOfficial Avatar answered Feb 06 '26 14:02

AmmarJavedOfficial



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!