- override
Determines the set of render objects located at the given position.
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.
The caller is responsible for transforming position into the local
coordinate space of the callee. The callee is responsible for checking
whether the given position is within its bounds.
Hit testing requires layout to be up-to-date but does not require painting
to be up-to-date. That means a render object can rely upon performLayout
having been called in hitTest but cannot rely upon paint having been
called. For example, a render object might be a child of a RenderOpacity
object, which calls hitTest on its children when its opacity is zero
even through it does not paint its children.
Source
@override
bool hitTest(HitTestResult result, { Point position }) {
_updateClip();
assert(_clip != null);
Point center = _clip.center;
// convert the position to an offset from the center of the unit circle
Offset offset = new Offset((position.x - center.x) / _clip.width,
(position.y - center.y) / _clip.height);
// check if the point is outside the unit circle
if (offset.distanceSquared > 0.25) // x^2 + y^2 > r^2
return false;
return super.hitTest(result, position: position);
}