postMessage method
Implementation
Future<String?> postMessage(String message) {
String escapedMessage =
message.replaceAll(RegExp('\"', multiLine: true), '\\"');
String invoker = '''
window.dispatchEvent(Object.assign(new CustomEvent('message'), {
data: "${escapedMessage}",
origin: 'kraken',
}));
'''
.trim();
// Wait until controller ready.
return _controller.future.then((WebViewController controller) {
return controller.evaluateJavascript(invoker);
});
}