measure static method

Size measure(
  1. String text, {
  2. TextStyle? style,
  3. TextDirection textDirection = TextDirection.ltr,
  4. double minWidth = 0.0,
  5. double maxWidth = double.infinity,
})

Measure the size of the text with the given configuration.

Implementation

static Size measure(
  String text, {
  TextStyle? style,
  TextDirection textDirection = TextDirection.ltr,
  double minWidth = 0.0,
  double maxWidth = double.infinity,
}) {
  // obviously, empty text always has zero size
  if (text.isEmpty) return Size.zero;

  final painter = TextPainter(
    text: TextSpan(text: text, style: style),
    textDirection: textDirection,
  );
  painter.layout(minWidth: minWidth, maxWidth: maxWidth);
  return painter.size;
}