measureText function

Size measureText(
  1. String textValue,
  2. TextStyle textStyle, [
  3. int? angle
])

This method measures the size for given text and textstyle

Implementation

Size measureText(String textValue, TextStyle textStyle, [int? angle]) {
  Size size;
  final TextPainter textPainter = TextPainter(
      textAlign: TextAlign.center,
      textDirection: TextDirection.ltr,
      text: TextSpan(text: textValue, style: textStyle));
  textPainter.layout();

  if (angle != null) {
    final Rect rect = rotatedTextSize(textPainter.size, angle);
    size = Size(rect.width, rect.height);
  } else {
    size = Size(textPainter.width, textPainter.height);
  }
  return size;
}