measure static method
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,
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;
}