diff --git a/packages/flutter/lib/src/rendering/flex.dart b/packages/flutter/lib/src/rendering/flex.dart index 4726bd4f01..45de3a51d1 100644 --- a/packages/flutter/lib/src/rendering/flex.dart +++ b/packages/flutter/lib/src/rendering/flex.dart @@ -308,6 +308,8 @@ enum CrossAxisAlignment { /// See also: /// /// * [RenderBox.getDistanceToBaseline], which defines the baseline of a box. + /// * [IgnoreBaseline], which can be used to ignore a child for the purpose of + /// baseline alignment. baseline; double _getChildCrossAxisOffset(double freeSpace, bool flipped) { @@ -821,13 +823,17 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin 10, + ); + final RenderConstrainedBox box2 = RenderConstrainedBox( + additionalConstraints: square, + child: RenderFlowBaselineTestBox() + ..gridCount = 1 + ..baselinePlacer = (double height) => 10, + ); + RenderConstrainedBox filler() => RenderConstrainedBox(additionalConstraints: square); + final RenderFlex flex = RenderFlex( + textDirection: TextDirection.ltr, + children: [ + filler(), + box1, + filler(), + box2, + filler(), + ], + direction: Axis.vertical, + ); + layout(flex, phase: EnginePhase.paint); + final double flexHeight = flex.size.height; + + // We can't call the getDistanceToBaseline method directly. Check the dry + // baseline instead, and in debug mode there are asserts that verify + // the two methods return the same results. + expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 100 + 10); + + flex.mainAxisAlignment = MainAxisAlignment.end; + pumpFrame(phase: EnginePhase.paint); + expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), flexHeight - 400 + 10); + + flex.verticalDirection = VerticalDirection.up; + pumpFrame(phase: EnginePhase.paint); + expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 300 + 10); + + flex.mainAxisAlignment = MainAxisAlignment.start; + pumpFrame(phase: EnginePhase.paint); + expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), flexHeight - 200 + 10); + }); + group('Intrinsics', () { test('main axis intrinsics with RenderAspectRatio 1', () { const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);