calculateTextWidth static method

double calculateTextWidth(
  1. BuildContext context,
  2. String value,
  3. dynamic fontSize,
  4. FontWeight fontWeight,
  5. double maxWidth,
  6. int maxLines,
)

Implementation

static double calculateTextWidth(BuildContext context, String value, fontSize,
    FontWeight fontWeight, double maxWidth, int maxLines) {
  value = filterText(value);
  TextPainter painter = TextPainter(

      ///AUTO:华为手机如果不指定locale的时候,该方法算出来的文字高度是比系统计算偏小的。
      locale: Localizations.localeOf(context),
      maxLines: maxLines,
      textDirection: TextDirection.ltr,
      text: TextSpan(
          text: value,
          style: TextStyle(
            fontWeight: fontWeight,
            fontSize: fontSize,
          )));
  painter.layout(maxWidth: maxWidth);

  ///文字的宽度:painter.width
  return painter.width;
}