textWidth method

double textWidth(
  1. String text
)

Calculates and returns the width of the given text, sized and spaced based on the current text configuration.

Implementation

double textWidth(String text) {
  final paragraphBuilder = ParagraphBuilder(ParagraphStyle(
    fontFamily: _fontName,
    fontSize: _fontSize,
    textAlign: _textAlignHorizontal.toFlutterAlign(),
  ))
    ..pushStyle(TextStyle(
      color: _paintingContext.fillPaint.color,
    ))
    ..addText(text);
  final paragraph = paragraphBuilder.build()
    ..layout(
      ParagraphConstraints(width: double.infinity),
    );
  return paragraph.maxIntrinsicWidth;
}