val paint=Paint()
paint.textSize=16F;
//Return the number of chars that the measured width exceeds maxWidth
val count=paint.breakText("hello world",true,100F,null);
//get width of the text
paint.measureText("hello world");
来自52659759的答案
扑朔迷离,可以做到这一点。
final render = RenderParagraph(TextSpan(text: "hello world",style: TextStyle(fontSize: 16)),textDirection: TextDirection.ltr);
render.layout(BoxConstraints());
//Return the number of chars that the measured width exceeds maxWidth
final position=render.getPositionForOffset(Offset(100, 0));
//get width of the text
final offset=render.getOffsetForCaret(position,Rect.largest);