globalToLocal method

Offset globalToLocal (Offset point, { RenderObject ancestor })

Convert the given point from the global coordinate system in logical pixels to the local coordinate system for this box.

If the transform from global coordinates to local coordinates is degenerate, this function returns Offset.zero.

If ancestor is non-null, this function converts the given point from the coordinate system of ancestor (which must be an ancestor of this render object) instead of from the global coordinate system.

This method is implemented in terms of getTransformTo.

Implementation

Offset globalToLocal(Offset point, { RenderObject ancestor }) {
  final Matrix4 transform = getTransformTo(ancestor);
  final double det = transform.invert();
  if (det == 0.0)
    return Offset.zero;
  return MatrixUtils.transformPoint(transform, point);
}