textWidth method

double textWidth(
  1. String text,
  2. TextStyle textStyle
)

Return the textwidth of the text in the given style

Implementation

double textWidth(String text, TextStyle textStyle) {
  return (TextPainter(
    text: TextSpan(text: text, style: textStyle),
    maxLines: 1,
    textDirection: TextDirection.ltr,
  )..layout())
      .size
      .width;
}