outOrNoWith static method

bool outOrNoWith(
  1. String text,
  2. double width,
  3. int lineNum,
  4. double fontSize,
)

判断字符串是否多余lineNum

Implementation

static bool outOrNoWith(String text, double width, int lineNum, double fontSize){

  var span = TextSpan(
    text: text,
    style: TextStyle(fontSize: fontSize),
  );
  var tp = TextPainter(
    maxLines: lineNum,
    textAlign: TextAlign.left,
    textDirection: TextDirection.ltr,
    text: span,
  );
  tp.layout(maxWidth: width);
  // whether the text overflowed or not
  return tp.didExceedMaxLines;
}