Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter GestureDetector click Issue – Button Outside Stack Not Clickable

I have a Flutter app where I’m trying to create an animated button interaction. When I click the first button, a second button should slide in from the left under the first button. The animation works as expected, but the problem is that the second button, when partially outside the Stack, is not clickable. Pls refer to this gif for better understanding.

enter image description here

The minor area near the white rectangle(near top right and bottom right corners) is clickable because it is not outside the stack. You can use this working example on DartPad.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m using Stack with clipBehavior set to Clip.none to allow the button to overflow the Stack. I’ve tried GestureDetector behavior to HitTestBehavior.translucent However, the area outside the Stack where the second button appears is not responsive to touch events.

I would like to make the second button clickable even when it’s outside the Stack. How can I achieve this behavior? Any guidance or suggestions would be greatly appreciated.

>Solution :

I’m not sure if this works in your case, because you work with animations here, but it should be the same:

Stack works with a RenderBox, which checks if the click is not outside the bounds of the stack.

Use the DeferPointer widget https://pub.dev/packages/defer_pointer

Typically in Flutter, if you offset a widget outside of it’s parent
bounds hit-testing will break. DeferPointer works around this issue by
handing off hit-testing and (optionally) rendering to an
DeferredPointerHandler widget further up the tree.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading