I have a flutter code snippet which listens for postMessage from my iframe page. (flutter_webview_plugin: ^0.3.9+1)
flutterWebviewPlugin.onStateChanged.listen((viewState) async {
String script = 'window.addEventListener("message", receiveMessage, false);' +
'function receiveMessage(event) {console.log(\'receiving data from child , data as follows: \',event.data)}';
flutterWebviewPlugin.evalJavascript(script);
}
I would like to trigger specific flutter functions if event.data returns a specific value , camera value would trigger my specific function that calls the camera plugin and so on. Meaning to say that my target iFrame will attempt to do a cross-origin communication via postMessage method.
For Cordova, I could do something like this:
window.addEventListener( "message" , function( event )
{
else if( event.data.indexOf( "camera" ) >= 0 )
{
//Trigger Camera Function
How do I go about doing this for flutter?
flutterWebviewPlugin.evalJavascript(script).then((result) {/* Do job*/});?