Skip to content

Commit 37b6eb2

Browse files
committed
Revert optimization to skip re-layout in step4
1 parent 42dc2ce commit 37b6eb2

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

packages/core/lib/src/widgets/html_table.dart

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ class _TableRenderLayouter {
383383
final children = step1.children;
384384
final remainingMaxWidth = step1.remainingMaxWidth;
385385

386+
final cellSizes = List<Size?>.filled(children.length, null);
386387
final childMinWidths = List<double?>.filled(children.length, null);
387-
final childSizes = List<Size?>.filled(children.length, null);
388388
final maxColumnWidths =
389389
step2.naiveColumnWidths.map((v) => v ?? .0).toList();
390390
final minColumnWidths = List.filled(step1.columnCount, .0);
@@ -396,7 +396,6 @@ class _TableRenderLayouter {
396396
(remainingMaxWidth == null || columnWidths.sum <= remainingMaxWidth)) {
397397
return _TableDataStep3(
398398
step2,
399-
childSizes: childSizes,
400399
columnWidths: columnWidths,
401400
);
402401
}
@@ -409,11 +408,11 @@ class _TableRenderLayouter {
409408
final child = children[i];
410409
final data = cells[i];
411410

412-
if (childSizes[i] == null) {
411+
if (cellSizes[i] == null) {
413412
// side effect
414413
// layout cells for the initial width
415414
final layoutSize = layouter(child, step1.widthConstraints);
416-
childSizes[i] = layoutSize;
415+
cellSizes[i] = layoutSize;
417416
maxColumnWidths.setMaxColumnWidths(tro, data, layoutSize.width);
418417
logger.fine('[3] Got child#$i $layoutSize@${step1.widthConstraints}');
419418
shouldLoop = true;
@@ -458,7 +457,6 @@ class _TableRenderLayouter {
458457

459458
return _TableDataStep3(
460459
step2,
461-
childSizes: childSizes,
462460
columnWidths: columnWidths,
463461
);
464462
}
@@ -506,7 +504,6 @@ class _TableRenderLayouter {
506504
final step1 = step2.step1;
507505
final cells = step1.cells;
508506
final children = step1.children;
509-
final existingChildSizes = step3.childSizes;
510507

511508
final childSizes = List.filled(children.length, Size.zero);
512509
final rowHeights = List.filled(step1.rowCount, .0);
@@ -515,19 +512,13 @@ class _TableRenderLayouter {
515512
final child = children[i];
516513
final data = cells[i];
517514

515+
// always re-layout because we cannot be sure whether
516+
// children will render the same inside an unconstrained and a tight box
518517
final childWidth = data.calculateWidth(tro, step3.columnWidths);
519-
var childSize = existingChildSizes[i];
520-
if (childSize?.width == childWidth) {
521-
// no need to re-layout if the width is the same
522-
childSizes[i] = childSize!;
523-
} else {
524-
// side effect
525-
// layout with tight constraints to get the expected width
526-
final cc1 = BoxConstraints.tightFor(width: childWidth);
527-
childSize = layouter(child, cc1);
528-
logger.fine('[4] Got child#$i $childSize@$cc1');
529-
childSizes[i] = childSize;
530-
}
518+
final cc1 = BoxConstraints.tightFor(width: childWidth);
519+
final childSize = layouter(child, cc1);
520+
logger.fine('[4] Got child#$i $childSize@$cc1');
521+
childSizes[i] = childSize;
531522

532523
// distribute cell height across spanned rows
533524
final rowHeight =
@@ -713,12 +704,10 @@ class _TableDataStep2 {
713704
class _TableDataStep3 {
714705
final _TableDataStep2 step2;
715706

716-
final List<Size?> childSizes;
717707
final List<double> columnWidths;
718708

719709
const _TableDataStep3(
720710
this.step2, {
721-
required this.childSizes,
722711
required this.columnWidths,
723712
});
724713
}

0 commit comments

Comments
 (0)