flutter计算文本内容行数
作者:
CodeLuck | 来源:发表于
2023-02-21 16:44 被阅读0次LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final span = TextSpan(
text: _textFieldController.text,
style: TextStyle(color: Color(0xff222222), fontSize: 28.w));
final tp = TextPainter(
text: span, maxLines: 2, textDirection: TextDirection.ltr);
tp.layout(maxWidth: constraints.maxWidth);
List aaa = tp.computeLineMetrics();
TextSelection selection = TextSelection(
baseOffset: 0, extentOffset: _textFieldController.text.length);
List<TextBox> boxes = tp.getBoxesForSelection(selection);
int numberOfLines = boxes.length;
print('lines:======= == ${aaa.length} === $numberOfLines');
}
)
本文标题:flutter计算文本内容行数
本文链接:https://www.haomeiwen.com/subject/vifokdtx.html
网友评论