I am working on a plugin that launches a WebView to carry out some auth verification. Using the webview_flutter plugin, it works fine on Android and iOS once I call the runJavascriptReturningResult
function. It returns the document.getElementById('return').innerText
and then I parse the result. But on Flutter web, the webview_flutter_web does not currently support runJavascriptReturningResult
, so it throws a platform error once invoked.
I tried using an HTML Popup, but I don't know how to extract the return data before the popup closes.
My implementation for the popup is like this:
html.WindowBase _popup = html.window.open(url, name,'left=100,top=100,width=800,height=600');
if (_popup.closed!) {
throw("Popups blocked");
}
How do I get the return data before the popup closes? Is there another way to do this on Flutter Web?
The solution was to listen to onMessage
. Then get the event data from it.
html.window.open(url!, 'new tab');
html.window.onMessage.listen((event) async {
log(event.data.toString()); // Prints out the Message
});