measure static method

TextPainter measure({
  1. required InlineSpan span,
  2. required double minWidth,
  3. required double maxWidth,
  4. TextAlign textAlign = TextAlign.start,
  5. TextDirection textDirection = TextDirection.ltr,
  6. double textScaleFactor = 1.0,
  7. required int maxLines,
  8. int widgetSpanCount = 0,
  9. bool bFindWidgetSpanCount = false,
})

Implementation

static TextPainter measure({
  required InlineSpan span,
  required double minWidth,
  required double maxWidth,
  TextAlign textAlign = TextAlign.start,
  TextDirection textDirection = TextDirection.ltr,
  double textScaleFactor = 1.0,
  required int maxLines,
  int widgetSpanCount = 0,
  bool bFindWidgetSpanCount = false,
}) {
  TextPainter textPainter = TextPainter(
    text: span,
    textDirection: TextDirection.ltr,
    maxLines: maxLines,
  );

  //这里有个官方Bug,测量时触发WidgetSpan的build方法,有个assert判断PlaceholderDimensions不为空,但实际上对测量和渲染无影响
  if (bFindWidgetSpanCount && widgetSpanCount <= 0) {
    List<PlaceholderDimensions>? value = buildWidgetSpanPlaceHolder(span);
    textPainter.setPlaceholderDimensions(value);
  }
  textPainter.layout(minWidth: minWidth, maxWidth: maxWidth);
  return textPainter;
}