preferredLineHeight property Null safety

double preferredLineHeight

The height of a space in text in logical pixels.

Not every line of text in text will have this height, but this height is "typical" for text in text and useful for sizing other objects relative a typical line of text.

Obtaining this value does not require calling layout.

The style of the text property is used to determine the font settings that contribute to the preferredLineHeight. If text is null or if it specifies no styles, the default TextStyle values are used (a 10 pixel sans-serif font).


double get preferredLineHeight {
  if (_layoutTemplate == null) {
    final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
    ); // direction doesn't matter, text is just a space
    if (text?.style != null)
      builder.pushStyle(text!.style!.getTextStyle(textScaleFactor: textScaleFactor));
    builder.addText(' ');
    _layoutTemplate =
      ..layout(const ui.ParagraphConstraints(width: double.infinity));
  return _layoutTemplate!.height;