From 9bf1793a109316e9d69f7183c4a05a37b3b3828b Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Tue, 28 Jul 2020 10:36:15 -0700 Subject: [PATCH] Fix crossSize for baseline (#62074) --- packages/flutter/lib/src/rendering/flex.dart | 2 +- packages/flutter/test/widgets/basic_test.dart | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/rendering/flex.dart b/packages/flutter/lib/src/rendering/flex.dart index f7941b73db..f26194dc11 100644 --- a/packages/flutter/lib/src/rendering/flex.dart +++ b/packages/flutter/lib/src/rendering/flex.dart @@ -854,7 +854,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin[ + Text('big text', + key: key1, + style: const TextStyle(fontSize: fontSize1), + ), + Text('one\ntwo\nthree\nfour\nfive\nsix\nseven', + key: key2, + style: const TextStyle(fontSize: fontSize2), + ), + const FlutterLogo(size: 250), + ], + ), + ), + ), + ), + ); + + final RenderBox textBox1 = tester.renderObject(find.byKey(key1)); + final RenderBox textBox2 = tester.renderObject(find.byKey(key2)); + final RenderBox rowBox = tester.renderObject(find.byType(Row)); + + // The two Texts are baseline aligned, so some portion of them extends + // both above and below the baseline. The first has a huge font size, so + // it extends higher above the baseline than usual. The second has many + // lines, but being aligned by the first line's baseline, they hang far + // below the baseline. The FlutterLogo extends further than both Texts, + // so the size of the parent row should contain the FlutterLogo as well. + const double ahemBaselineLocation = 0.8; // https://web-platform-tests.org/writing-tests/ahem.html + const double aboveBaseline1 = fontSize1 * ahemBaselineLocation; + const double aboveBaseline2 = fontSize2 * ahemBaselineLocation; + expect(rowBox.size.height, greaterThan(textBox1.size.height)); + expect(rowBox.size.height, greaterThan(textBox2.size.height)); + expect(rowBox.size.height, 250); + expect(tester.getTopLeft(find.byKey(key1)).dy, 0); + expect( + tester.getTopLeft(find.byKey(key2)).dy, + closeTo(aboveBaseline1 - aboveBaseline2, .001), + ); + }); }); test('UnconstrainedBox toString', () {