hitTestBoxChild method Null safety
- BoxHitTestResult result,
- RenderBox child,
- {required double mainAxisPosition,
- required double crossAxisPosition}
protected">@protected
Utility function for hitTestChildren for use when the children are RenderBox widgets.
This function takes care of converting the position from the sliver coordinate system to the Cartesian coordinate system used by RenderBox.
This function relies on childMainAxisPosition to determine the position of child in question.
Calling this for a child that is not visible is not valid.
Implementation
@protected
bool hitTestBoxChild(BoxHitTestResult result, RenderBox child, { required double mainAxisPosition, required double crossAxisPosition }) {
final bool rightWayUp = _getRightWayUp(constraints);
double delta = childMainAxisPosition(child);
final double crossAxisDelta = childCrossAxisPosition(child);
double absolutePosition = mainAxisPosition - delta;
final double absoluteCrossAxisPosition = crossAxisPosition - crossAxisDelta;
Offset paintOffset, transformedPosition;
assert(constraints.axis != null);
switch (constraints.axis) {
case Axis.horizontal:
if (!rightWayUp) {
absolutePosition = child.size.width - absolutePosition;
delta = geometry!.paintExtent - child.size.width - delta;
}
paintOffset = Offset(delta, crossAxisDelta);
transformedPosition = Offset(absolutePosition, absoluteCrossAxisPosition);
break;
case Axis.vertical:
if (!rightWayUp) {
absolutePosition = child.size.height - absolutePosition;
delta = geometry!.paintExtent - child.size.height - delta;
}
paintOffset = Offset(crossAxisDelta, delta);
transformedPosition = Offset(absoluteCrossAxisPosition, absolutePosition);
break;
}
assert(paintOffset != null);
assert(transformedPosition != null);
return result.addWithOutOfBandPosition(
paintOffset: paintOffset,
hitTest: (BoxHitTestResult result) {
return child.hitTest(result, position: transformedPosition);
},
);
}