calculateTextSize function

dynamic calculateTextSize(
  1. {required String text,
  2. required dynamic style}
)

Implementation

Size calculateTextSize({required String text, required TextStyle? style}) {
  final textPainter = TextPainter(
    text: TextSpan(
      text: text,
      style: style,
    ),
    textDirection: TextDirection.ltr,
  )..layout();

  return textPainter.size;
}