measureText static method
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(
// Merge with the ambient style so font family (Lexend), etc. match what `Text` renders.
text: TextSpan(text: text, style: DefaultTextStyle.of(context).style.merge(style)),
maxLines: 1,
textDirection: TextDirection.ltr,
textScaler: MediaQuery.textScalerOf(context),
)..layout();
return textPainter.width;
}