measureText function

Size measureText({
  1. required String text,
  2. required double scalar,
  3. required TextStyle? style,
})

Returns the soon-to-be rendered size of text via a TextPainter scalar should be the value from MediaQuery.of(context).textScaleFactor

Implementation

Size measureText({
  required String text,
  required double scalar,
  required TextStyle? style,
}) {
  final TextPainter textPainter = TextPainter(
    text: TextSpan(text: text, style: style),
    maxLines: 1,
    textScaleFactor: scalar,
    textDirection: TextDirection.ltr,
  )..layout();

  return textPainter.size;
}