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');
}
)
网友评论