Skip to content

Commit 88ffd89

Browse files
Implement computeDryBaseline for RenderWrap (#146260)
1 parent 730167e commit 88ffd89

File tree

3 files changed

+238
-179
lines changed

3 files changed

+238
-179
lines changed

packages/flutter/lib/src/rendering/table.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ class RenderTable extends RenderBox {
806806
double? _baselineDistance;
807807
@override
808808
double? computeDistanceToActualBaseline(TextBaseline baseline) {
809-
// returns the baseline of the first cell that has a baseline in the first row
809+
// returns the baseline offset of the cell in the first row with
810+
// the lowest baseline, and uses `TableCellVerticalAlignment.baseline`.
810811
assert(!debugNeedsLayout);
811812
return _baselineDistance;
812813
}
@@ -1026,6 +1027,36 @@ class RenderTable extends RenderBox {
10261027
return Rect.fromLTRB(0.0, _rowTops[row], size.width, _rowTops[row + 1]);
10271028
}
10281029

1030+
@override
1031+
double? computeDryBaseline(covariant BoxConstraints constraints, TextBaseline baseline) {
1032+
if (rows * columns == 0) {
1033+
return null;
1034+
}
1035+
final List<double> widths = _computeColumnWidths(constraints);
1036+
double? baselineOffset;
1037+
for (int col = 0; col < columns; col += 1) {
1038+
final RenderBox? child = _children[col];
1039+
final BoxConstraints childConstraints = BoxConstraints.tightFor(width: widths[col]);
1040+
if (child == null) {
1041+
continue;
1042+
}
1043+
final TableCellParentData childParentData = child.parentData! as TableCellParentData;
1044+
final double? childBaseline = switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) {
1045+
TableCellVerticalAlignment.baseline => child.getDryBaseline(childConstraints, baseline),
1046+
TableCellVerticalAlignment.baseline ||
1047+
TableCellVerticalAlignment.top ||
1048+
TableCellVerticalAlignment.middle ||
1049+
TableCellVerticalAlignment.bottom ||
1050+
TableCellVerticalAlignment.fill ||
1051+
TableCellVerticalAlignment.intrinsicHeight => null,
1052+
};
1053+
if (childBaseline != null && (baselineOffset == null || baselineOffset < childBaseline)) {
1054+
baselineOffset = childBaseline;
1055+
}
1056+
}
1057+
return baselineOffset;
1058+
}
1059+
10291060
@override
10301061
@protected
10311062
Size computeDryLayout(covariant BoxConstraints constraints) {

0 commit comments

Comments
 (0)