getCursorRectInView method

Rect? getCursorRectInView(
  1. TextEditingController controller
)

Get the cursor rect in coordinates relative to the Flutter view (window).

This accounts for the TextField's position within the widget tree.

Implementation

Rect? getCursorRectInView(TextEditingController controller) {
  final renderEditable = _renderEditable;
  if (renderEditable == null) return null;
  if (!controller.selection.isValid) return null;

  final localRect = renderEditable.getLocalRectForCaret(
    TextPosition(offset: controller.selection.baseOffset),
  );

  // Convert to view coordinates
  final editableOffset = renderEditable.localToGlobal(Offset.zero);
  return localRect.shift(editableOffset);
}