Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter for web - GestureDetector around RaisedButton

For context: https://dartpad.dev/c9689b40a5402e12538c726b5c0380ff

I have a GestureDetector (that has some specific business logic) that listens to single taps and has a child as parameter.

In a specific location, I want this child widget to look like a button. However, using a real button widget apparently skips the onTap of GestureDetector.

At first I thought that onTapCancel would then kick in, but for onTapCancel to trigger the widget needs to be 'long pressed'.

Any suggestions on how to solve this? (Using IgnorePointer around the child doesn't work.)

like image 661
Eric Avatar asked Feb 02 '26 02:02

Eric


1 Answers

AbsorbPointer

  Widget build(BuildContext context) {
    return GestureDetector(
        child: AbsorbPointer(child : child),
        onTap: () {
          print('tap');
          onTap();
        },
        onTapCancel: () {
          print('tapCancel');
        });
  }
like image 194
Kahou Avatar answered Feb 04 '26 14:02

Kahou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!