getLocalRectForCaret method Null safety

Rect getLocalRectForCaret(
  1. TextPosition caretPosition
)

Returns the Rect in local coordinates for the caret at the given text position.

See also:

Implementation

Rect getLocalRectForCaret(TextPosition caretPosition) {
  _computeTextMetricsIfNeeded();
  final Offset caretOffset = _textPainter.getOffsetForCaret(caretPosition, _caretPrototype);
  // This rect is the same as _caretPrototype but without the vertical padding.
  final Rect rect = Rect.fromLTWH(0.0, 0.0, cursorWidth, cursorHeight).shift(caretOffset + _paintOffset + cursorOffset);
  // Add additional cursor offset (generally only if on iOS).
  return rect.shift(_snapToPhysicalPixel(rect.topLeft));
}