我有一个Text小部件,如果它超过一定的大小,可以截断:
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 50.0),
child: Text(
widget.review,
overflow: TextOverflow.ellipsis,
)
);
Run Code Online (Sandbox Code Playgroud)
或最大行数:
RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: TextStyle(color: Colors.black),
text: widget.review,
));
Run Code Online (Sandbox Code Playgroud)
我的目标是只有在溢出完成后才能扩展文本.有没有正确的方法来检查文本是否溢出?
我发现在RichText中有一个RenderParagraph renderObject
,它有一个私有属性TextPainter _textPainter
,有一个bool didExceedMaxLines
.
简而言之,我只需要访问,richText.renderObject._textPainter.didExceedMaxLines
但正如您所看到的,它是使用下划线私有的.