textWidth function

double textWidth(
  1. String text,
  2. TextStyle style, {
  3. TextAlign textAlign = TextAlign.left,
})

Return the minWidth occupied by text in a single line

Implementation

double textWidth(String text, TextStyle style, {TextAlign textAlign = TextAlign.left}) {
  var span = TextSpan(text: text, style: style);
  var tp = TextPainter(maxLines: 1, textAlign: textAlign, textDirection: TextDirection.ltr, text: span);
  tp.layout();

  return tp.width;
}