flutter GestureDetector is not working with webview_flutter plugin

Viewed 15

I want to detect tap event on WebView. Here is my code:

@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
if (kDebugMode) {
print("tapped");
}
},
child: WebView(
initialUrl: "flutter.dev",
),
);
}

I had also tried HitTestBehavior.opaque property. Can you help me to solve this problem?

Thank you

1 Answers

Webview consume any gestures done on it.

You should also mention your use case for webview click.

But If you just want to check if user clicks on webview or not, you can cover it with a container using stack and detect click on that. but it will block any gesture on webview. Something like this -

Stack(
        children: <Widget>[
          Webview(),
          GestureDetector(
            onTap: () => print('tapped....'),
            child: Container(color: Colors.transparent)
          )
        ]
      )
Related