Skip to content

[two_dimensional_scrollables] Fix another combo of pinned/unpinned merged TableViewCells #6283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/two_dimensional_scrollables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.2

* Fixes a layout issue for unpinned merged cells that follow pinned table spans.
* Updates outdated sample code.

## 0.1.1

* Fixes a layout issue when pinned cells are merged.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ import 'table_span.dart';
/// ```dart
/// TableView.builder(
/// cellBuilder: (BuildContext context, TableVicinity vicinity) {
/// return Center(
/// child: Text('Cell ${vicinity.column} : ${vicinity.row}'),
/// return TableViewCell(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a way to analyze snippets in this repo, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I am aware of. I searched the repo for cases of this but did not find any.

/// child: Center(
/// child: Text('Cell ${vicinity.column} : ${vicinity.row}'),
/// ),
/// );
/// },
/// columnCount: 10,
Expand Down Expand Up @@ -809,10 +811,10 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
switch ((rowIsInPinnedColumn, rowIsPinned)) {
// Both row and column are pinned at this cell, or just pinned row.
(true, true) || (false, true) => 0.0,
// Cell is within a pinned column
(true, false) => _pinnedRowsExtent - verticalOffset.pixels,
// Cell is within a pinned row, or no pinned portion.
(false, false) => -verticalOffset.pixels,
// Cell is within a pinned column, or no pinned area at all.
(true, false) ||
(false, false) =>
_pinnedRowsExtent - verticalOffset.pixels,
};
mergedRowOffset = baseRowOffset +
_rowMetrics[firstRow]!.leadingOffset +
Expand All @@ -830,10 +832,10 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
switch ((columnIsInPinnedRow, columnIsPinned)) {
// Both row and column are pinned at this cell, or just pinned column.
(true, true) || (false, true) => 0.0,
// Cell is within a pinned row.
(true, false) => _pinnedColumnsExtent - horizontalOffset.pixels,
// No pinned portion.
(false, false) => -horizontalOffset.pixels,
// Cell is within a pinned row, or no pinned area at all.
(true, false) ||
(false, false) =>
_pinnedColumnsExtent - horizontalOffset.pixels,
};
mergedColumnOffset = baseColumnOffset +
_columnMetrics[firstColumn]!.leadingOffset +
Expand Down
2 changes: 1 addition & 1 deletion packages/two_dimensional_scrollables/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: two_dimensional_scrollables
description: Widgets that scroll using the two dimensional scrolling foundation.
version: 0.1.1
version: 0.1.2
repository: https://github.com/flutter/packages/tree/main/packages/two_dimensional_scrollables
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+two_dimensional_scrollables%22+

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,74 @@ void main() {
});
});
});

testWidgets(
'Merged unpinned cells following pinned cells are laid out correctly',
(WidgetTester tester) async {
final ScrollController verticalController = ScrollController();
final ScrollController horizontalController = ScrollController();
final Set<TableVicinity> mergedCell = <TableVicinity>{
const TableVicinity(row: 2, column: 2),
const TableVicinity(row: 3, column: 2),
const TableVicinity(row: 2, column: 3),
const TableVicinity(row: 3, column: 3),
};
final TableView tableView = TableView.builder(
columnCount: 10,
rowCount: 10,
columnBuilder: (_) => const TableSpan(extent: FixedTableSpanExtent(100)),
rowBuilder: (_) => const TableSpan(extent: FixedTableSpanExtent(100)),
cellBuilder: (BuildContext context, TableVicinity vicinity) {
if (mergedCell.contains(vicinity)) {
return const TableViewCell(
rowMergeStart: 2,
rowMergeSpan: 2,
columnMergeStart: 2,
columnMergeSpan: 2,
child: Text('Tile c: 2, r: 2'),
);
}
return TableViewCell(
child: Text('Tile c: ${vicinity.column}, r: ${vicinity.row}'),
);
},
pinnedRowCount: 1,
pinnedColumnCount: 1,
verticalDetails: ScrollableDetails.vertical(
controller: verticalController,
),
horizontalDetails: ScrollableDetails.horizontal(
controller: horizontalController,
),
);
await tester.pumpWidget(MaterialApp(home: tableView));
await tester.pumpAndSettle();

expect(verticalController.position.pixels, 0.0);
expect(horizontalController.position.pixels, 0.0);
expect(
tester.getRect(find.text('Tile c: 2, r: 2')),
const Rect.fromLTWH(200.0, 200.0, 200.0, 200.0),
);

verticalController.jumpTo(10.0);
await tester.pumpAndSettle();
expect(verticalController.position.pixels, 10.0);
expect(horizontalController.position.pixels, 0.0);
expect(
tester.getRect(find.text('Tile c: 2, r: 2')),
const Rect.fromLTWH(200.0, 190.0, 200.0, 200.0),
);

horizontalController.jumpTo(10.0);
await tester.pumpAndSettle();
expect(verticalController.position.pixels, 10.0);
expect(horizontalController.position.pixels, 10.0);
expect(
tester.getRect(find.text('Tile c: 2, r: 2')),
const Rect.fromLTWH(190.0, 190.0, 200.0, 200.0),
);
});
}

class _NullBuildContext implements BuildContext, TwoDimensionalChildManager {
Expand Down