getFullHeightForCaret method

double getFullHeightForCaret(
  1. TextPosition position,
  2. Rect caretPrototype
)

Returns the strut bounded height of the glyph at the given position.

Valid only after layout has been called.

Implementation

double getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
  // The if condition is derived from
  // https://github.com/google/skia/blob/0086a17e0d4cc676cf88cae671ba5ee967eb7241/modules/skparagraph/src/TextLine.cpp#L1244-L1246
  // which is set here:
  // https://github.com/flutter/engine/blob/a821b8790c9fd0e095013cd5bd1f20273bc1ee47/third_party/txt/src/skia/paragraph_builder_skia.cc#L134
  if (strutStyle == null || strutStyle == StrutStyle.disabled || strutStyle?.fontSize == 0.0) {
    final double? heightFromCaretMetrics = _computeCaretMetrics(position)?.height;
    if (heightFromCaretMetrics != null) {
      return heightFromCaretMetrics;
    }
  }
  final TextBox textBox = _getOrCreateLayoutTemplate().getBoxesForRange(0, 1, boxHeightStyle: ui.BoxHeightStyle.strut).single;
  return textBox.toRect().height;
}