2

I have a widget tree like:

Stack(
                          clipBehavior: Clip.none,
                          children: [
                            Container(
                              height: 20,
                              width: 100,
                              color: Colors.red,
                            ),
                            Positioned(
                                right: -10,
                                top: -20,
                                child: GestureDetector(
                                  behavior: HitTestBehavior.opaque,
                                  onTap: () {
                                    print('hello world');
                                  },
                                  child: Container(
                                    decoration: BoxDecoration(
                                        color: Colors.yellow,
                                        borderRadius:
                                            BorderRadius.circular(50.0),
                                        border: Border.all(
                                            color: Theme.of(context)
                                                .scaffoldBackgroundColor,
                                            width: 1.0)),
                                    height: 30,
                                    width: 30,
                                  ),
                                ))
                          ],
                        )

Gesture detector is only working for the region which lies inside the stack boundary (hence which is visible when clipBehavior is Clip.hardEdge,)
How to make the whole Gesture detector work or what could be an alternative approach to stack a clickable widget.

There are a lot of similar questions but I am not able to get the correct approach.

kanwar manraj
  • 492
  • 8
  • 26
  • Does this answer your question? [In Flutter, how can a positioned Widget feel taps outside of its parent Stack area?](https://stackoverflow.com/questions/51366761/in-flutter-how-can-a-positioned-widget-feel-taps-outside-of-its-parent-stack-ar) – Ivo Apr 04 '22 at 11:26
  • Just wrap the container with gestureDetector.NO need of potion – G H Prakash Apr 04 '22 at 11:28
  • I wanted to create a UI similar to this https://ibb.co/RzLV0dg, And I wanted the second widget in stack to be totally clickable @GHPrakash – kanwar manraj Apr 04 '22 at 13:06
  • I tested your code. It's working fine. went you click on the second widget (yellow circle) the log printing hello world.@kanwarmanraj – G H Prakash Apr 06 '22 at 04:47

1 Answers1

0

Your GestureDetecture is not working because of the overlapping of the red Container and blue container over each other, I don't know the exact reason

  1. but its woking by removing the red container
  2. or by wrapping the red with Positioned widget also