Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RenderFlex's baseline calculation with verticalDirection.up and Axis.vertical #148800

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/flutter/lib/src/rendering/flex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl

@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
return switch (_direction) {
Axis.horizontal => defaultComputeDistanceToHighestActualBaseline(baseline),
Axis.vertical => defaultComputeDistanceToFirstActualBaseline(baseline),
};
return defaultComputeDistanceToHighestActualBaseline(baseline);
}

static int _getFlex(RenderBox child) {
Expand Down
39 changes: 39 additions & 0 deletions packages/flutter/test/rendering/flex_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,45 @@ void main() {
expect(box2.localToGlobal(Offset.zero).dy, 0.0);
});

test('Vertical Flex Baseline', () {
const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
final RenderConstrainedBox box1 = RenderConstrainedBox(
additionalConstraints: square,
child: RenderFlowBaselineTestBox()
..gridCount = 1
..baselinePlacer = (double height) => 10,
);
final RenderConstrainedBox box2 = RenderConstrainedBox(
additionalConstraints: square,
child: RenderFlowBaselineTestBox()
..gridCount = 1
..baselinePlacer = (double height) => 10,
);
final RenderFlex flex = RenderFlex(
textDirection: TextDirection.ltr,
children: <RenderBox>[box1, box2],
direction: Axis.vertical,
);
layout(flex, phase: EnginePhase.paint);

// 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), 10);

flex.mainAxisAlignment = MainAxisAlignment.end;
pumpFrame(phase: EnginePhase.paint);
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 410);

flex.verticalDirection = VerticalDirection.up;
pumpFrame(phase: EnginePhase.paint);
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 10);

flex.mainAxisAlignment = MainAxisAlignment.start;
pumpFrame(phase: EnginePhase.paint);
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 410);
});

group('Intrinsics', () {
test('main axis intrinsics with RenderAspectRatio 1', () {
const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
Expand Down