childAtOffset method

RenderEditableBox? childAtOffset(
  1. Offset offset
)
inherited

Returns child of this container located at the specified local offset.

If offset is above this container (offset.dy is negative) returns the first child. Likewise, if offset is below this container then returns the last child.

Implementation

RenderEditableBox? childAtOffset(Offset offset) {
  assert(firstChild != null);
  _resolvePadding();

  if (offset.dy <= _resolvedPadding!.top) return firstChild;
  if (offset.dy >= size.height - _resolvedPadding!.bottom) return lastChild;

  var child = firstChild;
  var dy = _resolvedPadding!.top;
  var dx = -offset.dx;
  while (child != null) {
    if (child.size.contains(offset.translate(dx, -dy))) {
      return child;
    }
    dy += child.size.height;
    child = childAfter(child);
  }
  throw StateError('No child at offset $offset.');
}