Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop touch response for flutter_webview's WebView when I touch a floating button

Tags:

flutter

There is a GestureDetector above the WebView.

when I touch the GestureDetector, the WebView is also response touch event.

Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: <Widget>[
        WebView(
          initialUrl: url,
          javascriptMode: JavascriptMode.unrestricted
        ),
        GestureDetector(
          child:Image.asset('.....'),
          onTap:(){
            //do something
          }
        )
      ],
    ),
  );
}

How Can I stop WebView's touch response when I tap the GestureDetector?

like image 926
user8186372 Avatar asked Oct 23 '25 10:10

user8186372


1 Answers

I thhink this is what you need. AbsorbPointer is absorbing all the touches and doesn't allow WebView to get them.

Stack(
  children: <Widget>[
    AbsorbPointer(
      child: WebView(
        initialUrl: url,
        javascriptMode: JavascriptMode.unrestricted
      ),
    ),
    GestureDetector(
      child:Image.asset('.....'),
      onTap:(){
        //do something
      }
    )
  ],
);
like image 175
Andrey Turkovsky Avatar answered Oct 25 '25 01:10

Andrey Turkovsky