boundingTextSize static method

Size boundingTextSize(
  1. String text,
  2. TextStyle style, {
  3. int maxLines = 2 ^ 31,
  4. double maxWidth = double.infinity,
})

Implementation

static Size boundingTextSize(
  String text,
  TextStyle style, {
  int maxLines = 2 ^ 31,
  double maxWidth = double.infinity,
}) {
  if (text.isEmpty) {
    return Size.zero;
  }
  final TextPainter textPainter = TextPainter(
    textDirection: TextDirection.ltr,
    text: TextSpan(
      text: text,
      style: style,
    ),
    maxLines: maxLines,
  )..layout(maxWidth: maxWidth);
  return textPainter.size;
}