getPositionForOffset method

  1. @override
TextPosition getPositionForOffset(
  1. Offset offset
)
override

Returns the position within the text for the given pixel offset.

The offset parameter must be local to this box coordinate system.

Valid only after layout.

Implementation

@override
TextPosition getPositionForOffset(Offset offset) {
  final child = childAtOffset(offset)!;
  final parentData = child.parentData as BoxParentData;
  final localPosition =
      child.getPositionForOffset(offset - parentData.offset);
  return TextPosition(
    offset: localPosition.offset + child.getContainer().offset,
    affinity: localPosition.affinity,
  );
}