textSize static method

Size textSize(
  1. String text,
  2. TextStyle style
)

根据 TextStyle 计算 text 宽度。

Implementation

static Size textSize(String text, TextStyle style) {
  if (isEmpty(text)) return Size(0, 0);
  final TextPainter textPainter = TextPainter(
    text: TextSpan(text: text, style: style),
    maxLines: 1,
    textDirection: TextDirection.ltr,
  )..layout(minWidth: 0, maxWidth: double.infinity);
  return textPainter.size;
}