flutter-template
flutter-template copied to clipboard
Introduce getSize String extension
Size getSize(
TextStyle style, {
int maxLines = 1,
double minWidth = .0,
double maxWidth = double.infinity,
}) {
if (isNullOrBlank) {
return Size.zero;
}
final text = TextSpan(text: this, style: style);
final textPainter = TextPainter(
maxLines: maxLines,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
text: text,
);
textPainter.layout(minWidth: minWidth, maxWidth: maxWidth);
return textPainter.size;
}