Skip to content

Instantly share code, notes, and snippets.

@Saravana2
Created June 2, 2020 09:19
Show Gist options
  • Save Saravana2/4b63f168827d02180297864277e83041 to your computer and use it in GitHub Desktop.
Save Saravana2/4b63f168827d02180297864277e83041 to your computer and use it in GitHub Desktop.
In Flutter, touch and click events are not working in webview. so instead of write click event in dart.. write click event on Javascript by element tag name, class name or id
WebView(
initialUrl: "https://github.com/login",
onWebViewCreated: (controller) {
_myController = controller;
},
onPageFinished: (url) {
_myController.evaluateJavascript(
"document.getElementsByName('commit')[0].addEventListener('click',function(){ try { showResult.postMessage(document.getElementById('login_field').value); } catch (err) {} });");
},
onPageStarted: (url) {},
javascriptMode: JavascriptMode.unrestricted,
javascriptChannels: Set.from([
JavascriptChannel(
name: "showResult",
onMessageReceived: (JavascriptMessage result) {
if (result.message != null && result.message != "") {
// The result data will be stored in result.message
}}),]),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment