Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Hit Testing

Why your tap doesn't register: hit testing and the gesture arena

There is a specific kind of Flutter bug that eats an afternoon. The widget is on screen. The onTap is wired. You add a print statement and it never fires. Nothing in the console, no error, no warning — the tap simply does not exist. Every instance of this is one of two causes. Either the pointer never reached your detector during hit testing, or it reached it and the detector lost the gesture arena to something else. They are different problems with different fixes, and they are distinguishable. How a pointer finds a widget When a finger goes down, the framework walks the render tree from the root, asking each render object whether the point is inside it. The result is a hit test path : an ordered list from the deepest hit object up to the root. Pointer events are then dispatched along that path. Three rules explain most surprises: Hit testing is geometric, and it uses the render object’s box. Not its visual appearance. A Container with no colour and no child has zero size, s...