Closed themisir closed 3 years ago
From JS (I pass json string formatted as json):
let channelName = "FlutterChannel"
window["FlutterChannel"].postMessage('{"method": "myDartMethod"}');
From dart:
WebviewScaffold(
javascriptChannels: Set.from([
JavascriptChannel(
name: 'FlutterChannel',
onMessageReceived: (JavascriptMessage message) {
final decoded = json.decode(message.message);
String method = decoded["method"];
if (method == "myDartMethod") {
[your code here]
}
])
Thanks. So in JS I can post message using
window.[JavascriptChannel.name].postMessage(content);
In previous versions I had to send message with channel name to special function.
Use case
Currently
javascriptChannels
is not documented well.Proposal
For example it's not documented how to pass messages to js channel from html/js side to flutter.