Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gesture response outside of stack boundary not recieved

Tags:

flutter

dart

I am trying to implement a re-sizable widget with handles at the corners. The corner handles will be overflow the Stack by half of its width/height.

Issue: the outer part of handle does not report gesture events while the inner part is working fine.

It is intended or I am doing some thing wrong. If it is intended behavior then what to do next.

sample code

      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.green,
          body: Transform.translate(
            offset: boxOffset,
            child: Stack(
              overflow: Overflow.visible,
              fit: StackFit.expand,
              children: <Widget>[
                Container(
                  width: 100.0,
                  height: 100.0,
                  color: Colors.red,
                ),
                Positioned(
                  left: 100.0 - 20.0,
                  top: 100.0 - 20.0,
                  child: GestureDetector(
                    onTap: () {print("tapped");},
                    child: Container(
                      width: 80.0,
                      height: 80.0,
                      color: Colors.blue,
                    ),
                  ),
                )
              ],
            ),
          )
        );
    }

enter image description here

like image 617
Natwar Singh Avatar asked Jul 05 '18 09:07

Natwar Singh


People also ask

What is HitTestBehavior in flutter?

deferToChild → const HitTestBehavior. Targets that defer to their children receive events within their bounds only if one of their children is hit by the hit test.

What is stack overflow in flutter?

A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.


1 Answers

This is the desired behavior. If widgets could catch pointer events outside of their boundaries; it would be easy to fall into a situation where it's impossible to determine which widget is targeted.

In short, don't use overflow. Refactor your layout to make sure it's well contained inside the bounds of its parent.

like image 162
Rémi Rousselet Avatar answered Oct 14 '22 10:10

Rémi Rousselet