calculateTextWidth static method
double
calculateTextWidth(
- BuildContext context,
- String value,
- dynamic fontSize,
- FontWeight fontWeight,
- double maxWidth,
- int maxLines,
计算文本宽度
Implementation
static double calculateTextWidth(BuildContext context, String value, fontSize,
FontWeight fontWeight, double maxWidth, int maxLines) {
//创建painter
TextPainter painter = TextPainter(
locale: Localizations.maybeLocaleOf(context),
maxLines: maxLines,
textDirection: TextDirection.ltr,
text: TextSpan(
text: value,
style: TextStyle(
fontWeight: fontWeight,
fontSize: fontSize,
),
),
);
painter.layout(maxWidth: maxWidth);
return painter.width;
}