calculateTextWith method

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

Implementation

double calculateTextWith(
    String value,
    double? fontSize,
    FontWeight? fontWeight,
    double maxWidth,
    int maxLines,
    BuildContext context) {
  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;
}