findCaretOffsetInDocument static method

Offset findCaretOffsetInDocument([
  1. Finder? finder
])

Returns the (x,y) offset for the caret that's currently visible in the document.

Implementation

static Offset findCaretOffsetInDocument([Finder? finder]) {
  final caret = find.byKey(DocumentKeys.caret).evaluate().singleOrNull?.renderObject as RenderBox?;
  if (caret != null) {
    final globalCaretOffset = caret.localToGlobal(Offset.zero);
    final documentLayout = findDocumentLayout(finder);
    return documentLayout.getDocumentOffsetFromAncestorOffset(globalCaretOffset);
  }

  throw Exception('Could not locate caret in document');
}