measureText static method

double measureText(
  1. BuildContext context,
  2. String text,
  3. TextStyle style
)

Measures the width of a string with the given style and context.

Implementation

static double measureText(BuildContext context, String text, TextStyle style) {
  final textPainter = TextPainter(
    text: TextSpan(text: text, style: style),
    maxLines: 1,
    textDirection: TextDirection.ltr,
    textScaler: MediaQuery.textScalerOf(context),
  )..layout();
  return textPainter.width;
}