getPositionForOffset method

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

The offset parameter must be in global coordinates.

Implementation

@override
TextPosition getPositionForOffset(Offset offset) {
  final local = globalToLocal(offset);
  final child = childAtOffset(local)!;

  final parentData = child.parentData as BoxParentData;
  final localOffset = local - parentData.offset;
  final localPosition = child.getPositionForOffset(localOffset);
  return TextPosition(
    offset: localPosition.offset + child.node.offset,
    affinity: localPosition.affinity,
  );
}