Skip to content

Commit fc773f6

Browse files
committed
Rows that hug their cross axis and stretch give hugging children the thickest child's size, as the editor's solver does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjsYaRkTHNKszSHjd3j264
1 parent 65766db commit fc773f6

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

‎lib/src/transformers/node_transformers/passive_row_column_transformer.dart‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,19 @@ class PassiveRowColumnTransformer extends NodeWidgetTransformer<RowColumnNode> {
211211
// A parent that stretches its children across gives each one the full
212212
// cross axis, like the editor's solver, except a child that hugs on that
213213
// axis: the solver keeps its own size there and places it at the start.
214+
// In a parent that hugs the cross axis too (measured with an
215+
// IntrinsicHeight/Width), the solver stretches hugging children to the
216+
// thickest one, so cards in a row get equal heights.
217+
final bool parentHugsCross =
218+
(mainAxis == AxisC.horizontal
219+
? parentRowColumn.verticalFit
220+
: parentRowColumn.horizontalFit) ==
221+
SizeFit.shrinkWrap;
214222
final AlignmentGeometry? childAlignment =
215223
(alignment ?? node.alignment).data?.flutterAlignmentGeometry ??
216224
(parentRowColumn.crossAxisAlignment == CrossAxisAlignmentC.stretch &&
217-
crossAxisFit == SizeFit.shrinkWrap
225+
crossAxisFit == SizeFit.shrinkWrap &&
226+
!parentHugsCross
218227
? AlignmentDirectional.topStart
219228
: null);
220229
final bool hasAlignment = childAlignment != null;

‎test/stretch_row_test.dart‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:codelessly_api/codelessly_api.dart';
2+
import 'package:codelessly_sdk/codelessly_sdk.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
6+
import 'feedback_actions_test.dart' show body, canvas, layoutOf, pumpLayouts;
7+
8+
RowColumnNode card(String id, String content) => RowColumnNode(
9+
id: id,
10+
name: id,
11+
rowColumnType: RowColumnType.column,
12+
basicBoxLocal: NodeBox(0, 0, 150, 100),
13+
horizontalFit: SizeFit.expanded,
14+
verticalFit: SizeFit.shrinkWrap,
15+
fills: [PaintModel.solid(id: '$id fill', color: ColorRGB.black)],
16+
children: [content],
17+
)..parentID = 'cards';
18+
19+
RectangleNode block(String id, String parent, double height) => RectangleNode(
20+
id: id,
21+
name: id,
22+
basicBoxLocal: NodeBox(0, 0, 100, height),
23+
)..parentID = parent;
24+
25+
void main() {
26+
testWidgets('a row that hugs its height and stretches its children gives '
27+
"hugging cards the tallest card's height, as the editor lays it out", (
28+
tester,
29+
) async {
30+
await pumpLayouts(tester, [
31+
layoutOf('main', [
32+
canvas('main', 'mainBody'),
33+
body('mainBody', 'main', ['cards']),
34+
RowColumnNode(
35+
id: 'cards',
36+
name: 'cards',
37+
rowColumnType: RowColumnType.row,
38+
basicBoxLocal: NodeBox(0, 0, 390, 320),
39+
horizontalFit: SizeFit.expanded,
40+
verticalFit: SizeFit.shrinkWrap,
41+
crossAxisAlignment: CrossAxisAlignmentC.stretch,
42+
children: ['short', 'tall'],
43+
)..parentID = 'mainBody',
44+
card('short', 'shortBlock'),
45+
block('shortBlock', 'short', 200),
46+
card('tall', 'tallBlock'),
47+
block('tallBlock', 'tall', 320),
48+
]),
49+
]);
50+
expect(tester.getSize(find.byKey(const ValueKey('short')).first).height, 320);
51+
expect(tester.getSize(find.byKey(const ValueKey('tall')).first).height, 320);
52+
});
53+
}

0 commit comments

Comments
 (0)