diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 0ae5b470b1..79a15d5990 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -382,6 +382,8 @@ class RenderParagraph extends RenderBox RenderBox child = firstChild; final List placeholderDimensions = List(childCount); int childIndex = 0; + if (_applyTextScaleFactorToWidgetSpan) + height = height / textScaleFactor; while (child != null) { // Height and baseline is irrelevant as all text will be laid // out in a single line. @@ -400,6 +402,8 @@ class RenderParagraph extends RenderBox RenderBox child = firstChild; final List placeholderDimensions = List(childCount); int childIndex = 0; + if (_applyTextScaleFactorToWidgetSpan) + height = height / textScaleFactor; while (child != null) { final double intrinsicWidth = child.getMinIntrinsicWidth(height); final double intrinsicHeight = child.getMinIntrinsicHeight(intrinsicWidth); @@ -418,6 +422,8 @@ class RenderParagraph extends RenderBox RenderBox child = firstChild; final List placeholderDimensions = List(childCount); int childIndex = 0; + if (_applyTextScaleFactorToWidgetSpan) + width = width / textScaleFactor; while (child != null) { final double intrinsicHeight = child.getMinIntrinsicHeight(width); final double intrinsicWidth = child.getMinIntrinsicWidth(intrinsicHeight); diff --git a/packages/flutter/test/rendering/paragraph_test.dart b/packages/flutter/test/rendering/paragraph_test.dart index 70f17e0bcf..0d39bddb8a 100644 --- a/packages/flutter/test/rendering/paragraph_test.dart +++ b/packages/flutter/test/rendering/paragraph_test.dart @@ -326,6 +326,97 @@ void main() { expect(paragraph.locale, const Locale('ja', 'JP')); }); + test('can compute IntrinsicHeight for widget span', () { + // Regression test for https://github.com/flutter/flutter/issues/59316 + const double screenWidth = 100.0; + const String sentence = 'one two'; + List renderBoxes = [ + RenderParagraph(const TextSpan(text: sentence), textDirection: TextDirection.ltr), + ]; + RenderParagraph paragraph = RenderParagraph( + const TextSpan( + children: [ + WidgetSpan(child: Text(sentence)) + ] + ), + textScaleFactor: 1.0, + children: renderBoxes, + textDirection: TextDirection.ltr, + applyTextScaleFactorToWidgetSpan: true, + ); + layout(paragraph, constraints: const BoxConstraints(maxWidth: screenWidth)); + final double singleLineHeight = paragraph.computeMaxIntrinsicHeight(screenWidth); + expect(singleLineHeight, 14.0); + + pumpFrame(); + renderBoxes = [ + RenderParagraph(const TextSpan(text: sentence), textDirection: TextDirection.ltr), + ]; + paragraph = RenderParagraph( + const TextSpan( + children: [ + WidgetSpan(child: Text(sentence)) + ] + ), + textScaleFactor: 2.0, + children: renderBoxes, + textDirection: TextDirection.ltr, + applyTextScaleFactorToWidgetSpan: true, + ); + + layout(paragraph, constraints: const BoxConstraints(maxWidth: screenWidth)); + final double maxIntrinsicHeight = paragraph.computeMaxIntrinsicHeight(screenWidth); + final double minIntrinsicHeight = paragraph.computeMinIntrinsicHeight(screenWidth); + // intrinsicHeight = singleLineHeight * textScaleFactor * two lines. + expect(maxIntrinsicHeight, singleLineHeight * 2.0 * 2); + expect(maxIntrinsicHeight, minIntrinsicHeight); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020 + + test('can compute IntrinsicWidth for widget span', () { + // Regression test for https://github.com/flutter/flutter/issues/59316 + const double screenWidth = 1000.0; + const double fixedHeight = 1000.0; + const String sentence = 'one two'; + List renderBoxes = [ + RenderParagraph(const TextSpan(text: sentence), textDirection: TextDirection.ltr), + ]; + RenderParagraph paragraph = RenderParagraph( + const TextSpan( + children: [ + WidgetSpan(child: Text(sentence)) + ] + ), + textScaleFactor: 1.0, + children: renderBoxes, + textDirection: TextDirection.ltr, + applyTextScaleFactorToWidgetSpan: true, + ); + layout(paragraph, constraints: const BoxConstraints(maxWidth: screenWidth)); + final double widthForOneLine = paragraph.computeMaxIntrinsicWidth(fixedHeight); + expect(widthForOneLine, 98.0); + + pumpFrame(); + renderBoxes = [ + RenderParagraph(const TextSpan(text: sentence), textDirection: TextDirection.ltr), + ]; + paragraph = RenderParagraph( + const TextSpan( + children: [ + WidgetSpan(child: Text(sentence)) + ] + ), + textScaleFactor: 2.0, + children: renderBoxes, + textDirection: TextDirection.ltr, + applyTextScaleFactorToWidgetSpan: true, + ); + + layout(paragraph, constraints: const BoxConstraints(maxWidth: screenWidth)); + final double maxIntrinsicWidth = paragraph.computeMaxIntrinsicWidth(fixedHeight); + // maxIntrinsicWidth = widthForOneLine * textScaleFactor + expect(maxIntrinsicWidth, widthForOneLine * 2.0); + }, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020 + test('inline widgets test', () { const TextSpan text = TextSpan( text: 'a',