There are many answers to this regarding the flutter_webview package but not a single one for flutter_inappwebview which we are using for a few reasons.
So is there any way to fire up a method from anywhere inside the flutter widget tree that posts/sends anything to the inappwebview for which I can listen there with JS to do something (like a console.log with the received message)?
I also opened a github issue with a little more detail and a code snippet for this although I'm not sure how frequently the dev is looking for it (he has many issues there) so I figured asking the stackoverflow community makes sense. Here's the github issue for convenience: https://github.com/pichillilorenzo/flutter_inappwebview/issues/1037
you can trigger javascript function from flutter by following these steps
Need to execute evaluate javascript function from flutter as below
_webViewController.evaluateJavascript(source: """
var event = new CustomEvent("demoJavaScriptListener", {detail: {});
window.dispatchEvent(event); """);
Now in Javascript side you need write a listener as below
window.addEventListener("demoJavaScriptListener", (event) => {
console.log("My custom Event");
var map= JSON.parse(JSON.stringify(event.detail));
console.log("map",map);
});