1

I have a flutter application that contains a web page showing links fetched from the server using webview_flutter and webview_flutter_web , some times I need to get data from the webpage so that I change some behavior on my flutter menus and widgets. so am using the postMessage feature in Javascript to do it

Android

with android I have used it like this on JS:

Javascript:

 newPoint.postMessage(clickedPoint.lat() + "," + clickedPoint.lng());

Flutter:

JavascriptChannel(
  name: 'newPoint',
  onMessageReceived: (JavascriptMessage message) {
    homeController.getClickedPoint(message.message);
  }
),

And it worked as expected, but the problem appeared on the web version of the app

web

when I used the same method on the javascript to postMessage that I used with android it returned an error :

uncaught error : newPoint is not defined

So I did a little search and I found out that way :

window.postMessage({
  sender:"newPoint",
  message:clickedPoint.lat() + "," + clickedPoint.lng()
});

this way didn't return en error in console .. but it is not sending anything as it is not there at all .

So i need some help tp find the right method to it

ericmp
  • 1,163
  • 4
  • 18
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

0 Answers0