【发布时间】:2018-12-09 10:02:56
【问题描述】:
我有一个 Text 小部件,如果它超过一定大小,可以截断:
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 50.0),
child: Text(
widget.review,
overflow: TextOverflow.ellipsis,
)
);
或最大行数:
RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: TextStyle(color: Colors.black),
text: widget.review,
));
我的目标是让文本只有在发生溢出时才可展开。是否有适当的方法来检查文本是否溢出?
我尝试过的
我发现在 RichText 中有一个 RenderParagraph renderObject ,它有一个私有属性 TextPainter _textPainter 有一个 bool didExceedMaxLines。
简而言之,我只需要访问richText.renderObject._textPainter.didExceedMaxLines,但正如您所见,它是私有的,带有下划线。
【问题讨论】: