Future<Null> _launchInWebViewWithJavaScript(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: false,
enableJavaScript: true,
);
} else {
throw 'Could not launch $url';
}
}
onLoadStop: (controller, url) async {
var result = await controller.evaluateJavascript(source: "1 + 1");
print(result.runtimeType); // int
print(result); // 2
},
onWebViewCreated: (controller) {
// register a JavaScript handler with name "myHandlerName"
controller.addJavaScriptHandler(handlerName: 'myHandlerName', callback: (args) {
// print arguments coming from the JavaScript side!
print(args);
// return data to the JavaScript side!
return {
'bar': 'bar_value', 'baz': 'baz_value'
};
});
},