Unverified Commit b0b0e423 authored by hhh's avatar hhh Committed by GitHub

expose didExceedMaxLines from RenderParagraph (#139962)

I want to build a widget that adds some extra functionality when the inner text overflow. So the problem occurred, I can't find an elegant way to determine if the text is overflowing. 
So i expose `didExceedMaxLines` from `RenderParagraph`, I think it can make sense. Have there some advice?
parent b481f9c6
......@@ -1034,6 +1034,16 @@ class RenderParagraph extends RenderBox with ContainerRenderObjectMixin<RenderBo
return _textPainter.size;
}
/// Whether the text was truncated or ellipsized as laid out.
///
/// This returns the [TextPainter.didExceedMaxLines] of the underlying [TextPainter].
///
/// Valid only after [layout].
bool get didExceedMaxLines {
assert(!debugNeedsLayout);
return _textPainter.didExceedMaxLines;
}
/// Collected during [describeSemanticsConfiguration], used by
/// [assembleSemanticsNode] and [_combineSemanticsInfo].
List<InlineSpanSemanticsInformation>? _semanticsInfo;
......
......@@ -375,6 +375,41 @@ void main() {
expect(paragraph.size.height, 30.0);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61018
group('didExceedMaxLines', () {
RenderParagraph createRenderParagraph({
int? maxLines,
TextOverflow overflow = TextOverflow.clip,
}) {
return RenderParagraph(
const TextSpan(
text: 'Here is a long text, maybe exceed maxlines',
style: TextStyle(fontSize: 10.0),
),
textDirection: TextDirection.ltr,
overflow: overflow,
maxLines: maxLines,
);
}
test('none limited', () {
final RenderParagraph paragraph = createRenderParagraph();
layout(paragraph, constraints: const BoxConstraints(maxWidth: 100.0));
expect(paragraph.didExceedMaxLines, false);
});
test('limited by maxLines', () {
final RenderParagraph paragraph = createRenderParagraph(maxLines: 1);
layout(paragraph, constraints: const BoxConstraints(maxWidth: 100.0));
expect(paragraph.didExceedMaxLines, true);
});
test('limited by ellipsis', () {
final RenderParagraph paragraph = createRenderParagraph(overflow: TextOverflow.ellipsis);
layout(paragraph, constraints: const BoxConstraints(maxWidth: 100.0));
expect(paragraph.didExceedMaxLines, true);
});
});
test('changing color does not do layout', () {
final RenderParagraph paragraph = RenderParagraph(
const TextSpan(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment