Flutter PointerEvent vs OnTap, one works, the other doesn't

1,041

Since the button below the FloatingActionButton also has a listener, The Listener widget doesn't get's the PointerDown event. So to do that you have to change the behaviour to opaque so that both get the events.

Try Something like this:

Listener(
  behavior: HitTestBehavior.opaque,
  onPointerDown: (PointerDownEvent details){

  },
  child: ...,
)
Share:
1,041
Gary Frewin
Author by

Gary Frewin

Updated on December 19, 2022

Comments

  • Gary Frewin
    Gary Frewin over 1 year

    I have a stack widget I am trying to create in which: 1. The user touches the widget button triggering a pointerDown event. 2. Pointer down causes a slider type widget to scale from 0 to 100% from behind the button 3. With finger still down, the user drags to select a value on the scale 4. The value is selected by releasing the finger from the screen i.e. pointerUp.

    The widget works fine when I use onTap instead of pointerDown in step 1. But when I try to use a pointer down event, the _open method (that manages the scaleUp of the slider) isn't triggered.

    I have followed this example almost exactly: https://fireship.io/lessons/flutter-radial-menu-staggered-animations/, but have tried to change the touch event on the floatingActionbuton like this:

      Transform.scale(
                  scale: widget.scale.value,
                  child: Listener(
                      onPointerDown: (PointerDownEvent event) {
                        print('pointer is down');
                        setState(() {
                          _open;
                        });
                      },
                      child: FloatingActionButton(child: Icon(Icons.blur_circular), onPressed: () {})),
                )
    

    The print part detects and fires the event, but the _open method does not do anything and the menu part does not appear like in the tutorial link.

    I am at a loss.

  • Gary Frewin
    Gary Frewin about 4 years
    Unfortunately this hasn't changed the outcome. The print statement is still firing, just like before, and the animation doesn't fire. :/
  • Adnan karim
    Adnan karim about 4 years
    Im guessing _open is a function. Try calling _open()
  • Gary Frewin
    Gary Frewin about 4 years
    Damn, that was it. For onTap I was calling _open, but for onPointerDown I have to call _open()...