countTextWidgetSize static method
计算Text组件的宽高
Implementation
static Size countTextWidgetSize(
String text,
TextStyle style, {
int maxLines = 2 ^ 31,
double maxWidth = double.infinity,
}) {
if (text.isEmpty) {
return Size.zero;
}
final TextPainter textPainter = TextPainter(
text: TextSpan(text: text, style: style),
textDirection: TextDirection.ltr,
textWidthBasis: TextWidthBasis.longestLine,
maxLines: maxLines,
)..layout(maxWidth: maxWidth);
return textPainter.size;
}