在 Flutter 中,如何找到某个 (x,y) 位置的小部件?

In Flutter, how do I find a widget in some (x,y) position?

给定一些 (x,y) 坐标,以逻辑像素表示,相对于:

  1. 屏幕左上角。
  2. 某个容器的左上角。

我怎么知道哪个小部件在那个位置?

我认为您在使用 RenderBox class 中的 hitTest 方法。根据 documentation

Returns true if the given point is contained in this render object or one of its descendants. Adds any render objects that contain the point to the given hit test result.

因此您可以从关键上下文中获取小部件的 RenderBox 实例

GlobalKey key = new GlobalKey();
//your stuff
final RenderBox box = key.currentContext.findRenderObject()
// do box.hitTest