calculateTextSize function
Size
calculateTextSize({
- required String text,
- required TextStyle? style,
- required BuildContext context,
- double textScaleFactor = 1.0,
Implementation
Size calculateTextSize({
required String text,
required TextStyle? style,
required BuildContext context,
double textScaleFactor = 1.0,
}) {
final defaultTextStyle = DefaultTextStyle.of(context);
style = defaultTextStyle.style.merge(style);
final textPainter = TextPainter(
text: TextSpan(
text: text,
style: style,
),
textDirection: TextDirection.ltr,
)..layout();
return textPainter.size;
}