Skip to content

Commit 46aecbd

Browse files
committed
G-feedback
1 parent a817983 commit 46aecbd

1 file changed

Lines changed: 14 additions & 32 deletions

File tree

  • packages/two_dimensional_scrollables/lib/src/table_view

packages/two_dimensional_scrollables/lib/src/table_view/table.dart

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,7 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
629629
// If we are starting from 0, we should dispose of any metrics that are
630630
// no longer in use. This happens when the number of columns is reduced.
631631
if (!appendColumns) {
632-
_columnMetrics.removeWhere((int key, _Span span) {
633-
if (key >= column) {
634-
span.dispose();
635-
return true;
636-
}
637-
return false;
638-
});
632+
_disposeTrailingSpans(_columnMetrics, column);
639633
}
640634
final bool acceptedDimension = _updateHorizontalScrollBounds();
641635
if (!acceptedDimension) {
@@ -674,15 +668,7 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
674668
}
675669

676670
if (!appendColumns) {
677-
// If we are not appending, we should dispose of any metrics that are
678-
// no longer in use. This happens when the number of columns is reduced.
679-
_columnMetrics.removeWhere((int key, _Span span) {
680-
if (key >= column) {
681-
span.dispose();
682-
return true;
683-
}
684-
return false;
685-
});
671+
_disposeTrailingSpans(_columnMetrics, column);
686672
}
687673

688674
assert(_columnMetrics.length >= delegate.pinnedColumnCount);
@@ -755,13 +741,7 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
755741
// If we are starting from 0, we should dispose of any metrics that are
756742
// no longer in use. This happens when the number of rows is reduced.
757743
if (!appendRows) {
758-
_rowMetrics.removeWhere((int key, _Span span) {
759-
if (key >= row) {
760-
span.dispose();
761-
return true;
762-
}
763-
return false;
764-
});
744+
_disposeTrailingSpans(_rowMetrics, row);
765745
}
766746
final bool acceptedDimension = _updateVerticalScrollBounds();
767747
if (!acceptedDimension) {
@@ -800,20 +780,22 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
800780
}
801781

802782
if (!appendRows) {
803-
// If we are not appending, we should dispose of any metrics that are
804-
// no longer in use. This happens when the number of rows is reduced.
805-
_rowMetrics.removeWhere((int key, _Span span) {
806-
if (key >= row) {
807-
span.dispose();
808-
return true;
809-
}
810-
return false;
811-
});
783+
_disposeTrailingSpans(_rowMetrics, row);
812784
}
813785

814786
assert(_rowMetrics.length >= delegate.pinnedRowCount);
815787
}
816788

789+
void _disposeTrailingSpans(Map<int, _Span> metrics, int startIndex) {
790+
metrics.removeWhere((int key, _Span span) {
791+
if (key >= startIndex) {
792+
span.dispose();
793+
return true;
794+
}
795+
return false;
796+
});
797+
}
798+
817799
void _updateScrollBounds() {
818800
final bool acceptedDimension =
819801
_updateHorizontalScrollBounds() && _updateVerticalScrollBounds();

0 commit comments

Comments
 (0)