From fb33b7a1b86aacae45145e40f7946a4de62e3e9a Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 15 Oct 2019 10:17:52 -0700 Subject: [PATCH] Use placeholder dimensions that reflect the final text layout (#42558) The _computeChildren[Width/Height]With[Min/Max]Intrinsics methods in RenderParagraph overwrite the text painter's placeholder dimensions in order to compute potential widths and heights for the paragraph. The placeholder dimensions should be restored to the values computed by _layoutChildren before painting the text. --- bin/internal/goldens.version | 2 +- packages/flutter/lib/src/rendering/paragraph.dart | 13 ++++++++++--- packages/flutter/test/widgets/text_golden_test.dart | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/internal/goldens.version b/bin/internal/goldens.version index db957bdeb5..278ccf4ed1 100644 --- a/bin/internal/goldens.version +++ b/bin/internal/goldens.version @@ -1 +1 @@ -fa13c1b039e693123888e434e4ee1f9ff79d3b6e +65bd07204149c4f7612bbf179cf088a2d69ca549 diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index e01b7c2088..d17b0d46fe 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -488,7 +488,15 @@ class RenderParagraph extends RenderBox _textPainter.markNeedsLayout(); } + // Placeholder dimensions representing the sizes of child inline widgets. + // + // These need to be cached because the text painter's placeholder dimensions + // will be overwritten during intrinsic width/height calculations and must be + // restored to the original values before final layout and painting. + List _placeholderDimensions; + void _layoutTextWithConstraints(BoxConstraints constraints) { + _textPainter.setPlaceholderDimensions(_placeholderDimensions); _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); } @@ -501,7 +509,7 @@ class RenderParagraph extends RenderBox return; } RenderBox child = firstChild; - final List placeholderDimensions = List(childCount); + _placeholderDimensions = List(childCount); int childIndex = 0; while (child != null) { // Only constrain the width to the maximum width of the paragraph. @@ -525,7 +533,7 @@ class RenderParagraph extends RenderBox break; } } - placeholderDimensions[childIndex] = PlaceholderDimensions( + _placeholderDimensions[childIndex] = PlaceholderDimensions( size: child.size, alignment: _placeholderSpans[childIndex].alignment, baseline: _placeholderSpans[childIndex].baseline, @@ -534,7 +542,6 @@ class RenderParagraph extends RenderBox child = childAfter(child); childIndex += 1; } - _textPainter.setPlaceholderDimensions(placeholderDimensions); } // Iterate through the laid-out children and set the parentData offsets based diff --git a/packages/flutter/test/widgets/text_golden_test.dart b/packages/flutter/test/widgets/text_golden_test.dart index 5bf078cb7f..f4a464b0de 100644 --- a/packages/flutter/test/widgets/text_golden_test.dart +++ b/packages/flutter/test/widgets/text_golden_test.dart @@ -831,7 +831,7 @@ void main() { find.byType(Container), matchesGoldenFile( 'text_golden.TextInlineWidgetNest.1.png', - version: 2, + version: 3, ), ); });