calculateOffsetForCaret static method

Offset calculateOffsetForCaret(
  1. DocumentPosition position, [
  2. Finder? finder
])

Returns the (x,y) offset for a caret, if that caret appeared at the given position.

By default, this method expects a single SuperReader in the widget tree and finds it byType. To specify one SuperReader among many, pass a superDocumentFinder.

Implementation

static Offset calculateOffsetForCaret(DocumentPosition position, [Finder? finder]) {
  final documentLayout = _findDocumentLayout(finder);
  final positionRect = documentLayout.getRectForPosition(position);
  assert(positionRect != null);
  return positionRect!.topLeft;
}