getFontWidth method

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

Implementation

double getFontWidth(String text, TextStyle style, BuildContext context) {
  TextPainter textPainter = TextPainter(
      text: TextSpan(text: text, style: style),
      maxLines: 1,
      textScaleFactor: MediaQuery.of(context).textScaleFactor,
      textDirection: TextDirection.ltr)
    ..layout();
  return textPainter.size.width;
}