diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 669e8c18d7..6585cacf0e 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -513,7 +513,7 @@ class RenderParagraph extends RenderBox void _setParentData() { RenderBox child = firstChild; int childIndex = 0; - while (child != null) { + while (child != null && childIndex < _textPainter.inlinePlaceholderBoxes.length) { final TextParentData textParentData = child.parentData; textParentData.offset = Offset( _textPainter.inlinePlaceholderBoxes[childIndex].left, @@ -640,8 +640,11 @@ class RenderParagraph extends RenderBox RenderBox child = firstChild; int childIndex = 0; - while (child != null) { - assert(childIndex < _textPainter.inlinePlaceholderBoxes.length); + // childIndex might be out of index of placeholder boxes. This can happen + // if engine truncates children due to ellipsis. Sadly, we would not know + // it until we finish layout, and RenderObject is in immutable state at + // this point. + while (child != null && childIndex < _textPainter.inlinePlaceholderBoxes.length) { final TextParentData textParentData = child.parentData; final double scale = textParentData.scale; diff --git a/packages/flutter/test/widgets/text_test.dart b/packages/flutter/test/widgets/text_test.dart index cb97cb54da..075f036698 100644 --- a/packages/flutter/test/widgets/text_test.dart +++ b/packages/flutter/test/widgets/text_test.dart @@ -116,6 +116,37 @@ void main() { expect(text.text.style.fontSize, 20.0); }); + testWidgets('inline widgets works with ellipsis', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/35869 + const TextStyle textStyle = TextStyle(fontFamily: 'Ahem'); + await tester.pumpWidget( + Text.rich( + TextSpan( + children: [ + const TextSpan(text: 'a very very very very very very very very very very long line'), + WidgetSpan( + child: SizedBox( + width: 20, + height: 40, + child: Card( + child: RichText( + text: const TextSpan(text: 'widget should be truncated'), + textDirection: TextDirection.rtl, + ), + ), + ), + ), + ], + style: textStyle, + ), + textDirection: TextDirection.ltr, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ); + expect(tester.takeException(), null); + }); + testWidgets('semanticsLabel can override text label', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget(