textSizeWidthContext method
maxLines 不生效,只可以根据宽度计算高度,所以这里只有一行。
Implementation
double textSizeWidthContext({BuildContext? context, TextStyle? style}) {
final Size size = (TextPainter(
text: TextSpan(text: this, style: style),
maxLines: 1,
textScaleFactor: context != null ? MediaQuery.of(context).textScaleFactor : 1.0,
textDirection: TextDirection.ltr)
..layout())
.size;
return size.width;
}