hitTestChildren method

  1. @override
bool hitTestChildren (HitTestResult result, { Offset position })
override

Override this method to check whether any children are located at the given position.

Typically children should be hit-tested in reverse paint order so that hit tests at locations where children overlap hit the child that is visually "on top" (i.e., paints later).

The caller is responsible for transforming position from global coordinates to its location relative to the origin of this RenderBox. This RenderBox is responsible for checking whether the given position is within its bounds.

Used by hitTest. If you override hitTest and do not call this function, then you don't need to implement this function.

Implementation

@override
bool hitTestChildren(HitTestResult result, { Offset position }) {
  double mainAxisPosition, crossAxisPosition;
  switch (axis) {
    case Axis.vertical:
      mainAxisPosition = position.dy;
      crossAxisPosition = position.dx;
      break;
    case Axis.horizontal:
      mainAxisPosition = position.dx;
      crossAxisPosition = position.dy;
      break;
  }
  assert(mainAxisPosition != null);
  assert(crossAxisPosition != null);
  for (RenderSliver child in childrenInHitTestOrder) {
    if (child.geometry.visible && child.hitTest(
      result,
      mainAxisPosition: computeChildMainAxisPosition(child, mainAxisPosition),
      crossAxisPosition: crossAxisPosition
    )) {
      return true;
    }
  }
  return false;
}