getPositionBelow method Null safety

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

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.


TextPosition? getPositionBelow(TextPosition position) {
  assert(position.offset < getContainer().length);

  final child = childAtPosition(position);
  final childLocalPosition =
      TextPosition(offset: position.offset - child.getContainer().offset);
  final result = child.getPositionBelow(childLocalPosition);
  if (result != null) {
    return TextPosition(offset: result.offset + child.getContainer().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.getContainer().offset +