getPositionBelow method

  1. @override
TextPosition? getPositionBelow(
  1. TextPosition position
)
override

Returns the position within the text which is on the line below the given position.

The position parameter must be relative to the node content.

Primarily used with multi-line or soft-wrapping text.

Can return null which indicates that the position is at the bottommost line in the text already.

Implementation

@override
TextPosition? getPositionBelow(TextPosition position) {
  assert(position.offset < container.length);

  final child = childAtPosition(position);
  final childLocalPosition = TextPosition(offset: position.offset - child.container.offset);
  final result = child.getPositionBelow(childLocalPosition);
  if (result != null) {
    return TextPosition(offset: result.offset + child.container.offset);
  }

  final sibling = childAfter(child);
  if (sibling == null) {
    return null;
  }

  final caretOffset = child.getOffsetForCaret(childLocalPosition);
  final testOffset = sibling.getOffsetForCaret(const TextPosition(offset: 0));
  final finalOffset = Offset(caretOffset.dx, testOffset.dy);
  return TextPosition(offset: sibling.container.offset + sibling.getPositionForOffset(finalOffset).offset);
}