Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Optimize build calls
  • Loading branch information
Piinks committed Jan 23, 2024
commit 4960a25855afeb4dc23a843a0bf10249155814fe
25 changes: 5 additions & 20 deletions packages/two_dimensional_scrollables/example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "f1fefa8315ccf7081343d50815809dc3c7d5f347"
revision: "3a4f5779c1372f29a2eb181aedd796dba7a720c8"
channel: "[user-branch]"

project_type: app
Expand All @@ -13,26 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
- platform: android
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
- platform: ios
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
- platform: linux
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
create_revision: 3a4f5779c1372f29a2eb181aedd796dba7a720c8
base_revision: 3a4f5779c1372f29a2eb181aedd796dba7a720c8
- platform: macos
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
- platform: web
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
- platform: windows
create_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
base_revision: f1fefa8315ccf7081343d50815809dc3c7d5f347
create_revision: 3a4f5779c1372f29a2eb181aedd796dba7a720c8
base_revision: 3a4f5779c1372f29a2eb181aedd796dba7a720c8

# User provided section

Expand Down
51 changes: 26 additions & 25 deletions packages/two_dimensional_scrollables/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ class TableExample extends StatefulWidget {

class _TableExampleState extends State<TableExample> {
final Map<TableVicinity, (int, int)> mergedRows = <TableVicinity, (int, int)>{
// TableVicinity in merged cell : (start, span)
// TableVicinity.zero : (0, 2),
// TableVicinity.zero.copyWith(row: 1) : (0, 2),
// const TableVicinity(row: 1, column: 1) : (1, 2),
// const TableVicinity(row: 2, column: 1) : (1, 2),
const TableVicinity(row: 2, column: 2) : (2, 2),
const TableVicinity(row: 2, column: 3) : (2, 2),
const TableVicinity(row: 3, column: 2) : (2, 2),
const TableVicinity(row: 3, column: 3) : (2, 2),
const TableVicinity(row: 0, column: 0) : (0, 3),
const TableVicinity(row: 1, column: 0) : (0, 3),
const TableVicinity(row: 2, column: 0) : (0, 3),
const TableVicinity(row: 0, column: 1) : (0, 3),
const TableVicinity(row: 1, column: 1) : (0, 3),
const TableVicinity(row: 2, column: 1) : (0, 3),
const TableVicinity(row: 0, column: 2) : (0, 3),
const TableVicinity(row: 1, column: 2) : (0, 3),
const TableVicinity(row: 2, column: 2) : (0, 3),
};

final Map<TableVicinity, (int, int)> mergedColumns = <TableVicinity, (int, int)>{
// TableVicinity in merged cell : (start, span)
// TableVicinity.zero.copyWith(column: 2) : (2, 2),
// TableVicinity.zero.copyWith(column: 3) : (2, 2),
// const TableVicinity(row: 3, column: 0) : (0, 2),
// const TableVicinity(row: 3, column: 1) : (0, 2),
const TableVicinity(row: 2, column: 2) : (2, 2),
const TableVicinity(row: 2, column: 3) : (2, 2),
const TableVicinity(row: 3, column: 2) : (2, 2),
const TableVicinity(row: 3, column: 3) : (2, 2),
};
// final Map<TableVicinity, (int, int)> mergedColumns = <TableVicinity, (int, int)>{
// // TableVicinity in merged cell : (start, span)
// // TableVicinity.zero.copyWith(column: 2) : (2, 2),
// // TableVicinity.zero.copyWith(column: 3) : (2, 2),
// // const TableVicinity(row: 3, column: 0) : (0, 2),
// // const TableVicinity(row: 3, column: 1) : (0, 2),
// const TableVicinity(row: 2, column: 2) : (2, 2),
// const TableVicinity(row: 2, column: 3) : (2, 2),
// const TableVicinity(row: 3, column: 2) : (2, 2),
// const TableVicinity(row: 3, column: 3) : (2, 2),
// };

@override
Widget build(BuildContext context) {
Expand All @@ -73,21 +73,22 @@ class _TableExampleState extends State<TableExample> {
),
body: TableView.builder(
cellBuilder: _buildCell,
columnCount: 4,
columnCount: 3,
columnBuilder: _buildColumnSpan,
rowCount: 4,
rowCount: 3,
rowBuilder: _buildRowSpan,
),
);
}

TableViewCell _buildCell(BuildContext context, TableVicinity vicinity) {
if (mergedColumns.keys.contains(vicinity) || mergedRows.keys.contains(vicinity)) {
print('build called');
if (mergedRows.keys.contains(vicinity)) { // || mergedRows.keys.contains(vicinity)) {
return TableViewCell(
rowMergeStart: mergedRows[vicinity]?.$1,
rowMergeSpan: mergedRows[vicinity]?.$2,
columnMergeStart: mergedColumns[vicinity]?.$1,
columnMergeSpan: mergedColumns[vicinity]?.$2,
columnMergeStart: mergedRows[vicinity]?.$1,
columnMergeSpan: mergedRows[vicinity]?.$2,
child: const Center(
child: Text('Merged'),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
required int pinnedSpanCount,
required TableVicinity currentVicinity,
}) {
if (spanMergeStart == spanMergeEnd) {
// Not merged
return true;
}

final String lowerSpanOrientation = spanOrientation.toLowerCase();
assert(
spanMergeStart <= currentSpan,
Expand Down Expand Up @@ -740,22 +745,23 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
xPaintOffset += colSpan.configuration.padding.leading;

final TableVicinity vicinity = TableVicinity(column: column, row: row);
RenderBox? cell;
if (!_mergedVicinities.keys.contains(vicinity)) {
// We do not call build for vicinities that are already covered by a
// merged cell.
cell = buildOrObtainChildFor(vicinity);
}
final RenderBox? cell = _mergedVicinities.keys.contains(vicinity) ? null : buildOrObtainChildFor(vicinity);

if (cell != null) {
final TableViewParentData cellParentData = parentDataOf(cell);

// Merged row handling
if (cellParentData.rowMergeStart != null) {
final int rowMergeStart = cellParentData.rowMergeStart!;
_mergedRows.add(rowMergeStart);
final int lastRow =
rowMergeStart + cellParentData.rowMergeSpan! - 1;
// Merged cell handling
if (cellParentData.rowMergeStart != null || cellParentData.columnMergeStart != null) {
late final int rowMergeStart;
late final int lastRow;
if (cellParentData.rowMergeStart != null) {
rowMergeStart = cellParentData.rowMergeStart!;
lastRow = rowMergeStart + cellParentData.rowMergeSpan! - 1;
_mergedRows.add(rowMergeStart);
} else {
rowMergeStart = row;
lastRow = row;
}
assert(_debugCheckMergeBounds(
spanOrientation: 'Row',
currentSpan: row,
Expand All @@ -765,28 +771,17 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
pinnedSpanCount: delegate.pinnedRowCount,
currentVicinity: vicinity,
));
// Compute height and layout offset for merged rows.
final _Span firstRow = _rowMetrics[rowMergeStart]!;
mergedRowHeight = firstRow.extent;
mergedYPaintOffset = -verticalOffset.pixels +
firstRow.leadingOffset +
firstRow.configuration.padding.leading;
_mergedVicinities[vicinity.copyWith(row: rowMergeStart)] = vicinity;
int nextRow = rowMergeStart + 1;
while (nextRow <= lastRow) {
_mergedRows.add(nextRow);
_mergedVicinities[vicinity.copyWith(row: nextRow)] = vicinity;
mergedRowHeight = mergedRowHeight! + _rowMetrics[nextRow]!.extent;
nextRow++;
}
}

// Merged column handling.
if (cellParentData.columnMergeStart != null) {
final int columnMergeStart = cellParentData.columnMergeStart!;
_mergedColumns.add(columnMergeStart);
final int lastColumn =
columnMergeStart + cellParentData.columnMergeSpan! - 1;
late final int columnMergeStart;
late final int lastColumn;
if (cellParentData.columnMergeStart != null) {
columnMergeStart = cellParentData.columnMergeStart!;
lastColumn = columnMergeStart + cellParentData.columnMergeSpan! - 1;
_mergedColumns.add(columnMergeStart);
} else {
columnMergeStart = column;
lastColumn = column;
}
assert(_debugCheckMergeBounds(
spanOrientation: 'Column',
currentSpan: column,
Expand All @@ -796,22 +791,34 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
pinnedSpanCount: delegate.pinnedColumnCount,
currentVicinity: vicinity,
));

// Compute height and layout offset for merged rows.
final _Span firstRow = _rowMetrics[rowMergeStart]!;
mergedRowHeight = firstRow.extent;
mergedYPaintOffset = -verticalOffset.pixels +
firstRow.leadingOffset +
firstRow.configuration.padding.leading;
// Compute width and layout offset for merged columns.
final _Span firstColumn = _columnMetrics[columnMergeStart]!;
mergedColumnWidth = firstColumn.extent;
mergedXPaintOffset = -horizontalOffset.pixels +
firstColumn.leadingOffset +
firstColumn.configuration.padding.leading;
_mergedVicinities[vicinity.copyWith(column: columnMergeStart)] =
vicinity;
int nextColumn = columnMergeStart + 1;
while (nextColumn <= lastColumn) {
_mergedColumns.add(nextColumn);
_mergedVicinities[vicinity.copyWith(column: nextColumn)] =
vicinity;
mergedColumnWidth =
mergedColumnWidth! + _columnMetrics[nextColumn]!.extent;
nextColumn++;

int currentRow = rowMergeStart;
while (currentRow <= lastRow) {
_mergedRows.add(currentRow);
mergedRowHeight = mergedRowHeight! + _rowMetrics[currentRow]!.extent;
int currentColumn = columnMergeStart;
while (currentColumn <= lastColumn) {
_mergedColumns.add(currentColumn);
mergedColumnWidth =
mergedColumnWidth! + _columnMetrics[currentColumn]!.extent;
_mergedVicinities[TableVicinity(row: currentRow, column: currentColumn,)] =
vicinity;
currentColumn++;
}
currentRow++;
}
}

Expand Down