Skip to content

Commit 0badb43

Browse files
authored
[two_dimensional_scrollables] Fix another combo of pinned/unpinned merged TableViewCells (flutter#6283)
Fixes flutter/flutter#144100 Picks up doc fix from flutter#6154 as well
1 parent 903f03a commit 0badb43

File tree

4 files changed

+86
-11
lines changed

4 files changed

+86
-11
lines changed

packages/two_dimensional_scrollables/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.2
2+
3+
* Fixes a layout issue for unpinned merged cells that follow pinned table spans.
4+
* Updates outdated sample code.
5+
16
## 0.1.1
27

38
* Fixes a layout issue when pinned cells are merged.

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ import 'table_span.dart';
4949
/// ```dart
5050
/// TableView.builder(
5151
/// cellBuilder: (BuildContext context, TableVicinity vicinity) {
52-
/// return Center(
53-
/// child: Text('Cell ${vicinity.column} : ${vicinity.row}'),
52+
/// return TableViewCell(
53+
/// child: Center(
54+
/// child: Text('Cell ${vicinity.column} : ${vicinity.row}'),
55+
/// ),
5456
/// );
5557
/// },
5658
/// columnCount: 10,
@@ -809,10 +811,10 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
809811
switch ((rowIsInPinnedColumn, rowIsPinned)) {
810812
// Both row and column are pinned at this cell, or just pinned row.
811813
(true, true) || (false, true) => 0.0,
812-
// Cell is within a pinned column
813-
(true, false) => _pinnedRowsExtent - verticalOffset.pixels,
814-
// Cell is within a pinned row, or no pinned portion.
815-
(false, false) => -verticalOffset.pixels,
814+
// Cell is within a pinned column, or no pinned area at all.
815+
(true, false) ||
816+
(false, false) =>
817+
_pinnedRowsExtent - verticalOffset.pixels,
816818
};
817819
mergedRowOffset = baseRowOffset +
818820
_rowMetrics[firstRow]!.leadingOffset +
@@ -830,10 +832,10 @@ class RenderTableViewport extends RenderTwoDimensionalViewport {
830832
switch ((columnIsInPinnedRow, columnIsPinned)) {
831833
// Both row and column are pinned at this cell, or just pinned column.
832834
(true, true) || (false, true) => 0.0,
833-
// Cell is within a pinned row.
834-
(true, false) => _pinnedColumnsExtent - horizontalOffset.pixels,
835-
// No pinned portion.
836-
(false, false) => -horizontalOffset.pixels,
835+
// Cell is within a pinned row, or no pinned area at all.
836+
(true, false) ||
837+
(false, false) =>
838+
_pinnedColumnsExtent - horizontalOffset.pixels,
837839
};
838840
mergedColumnOffset = baseColumnOffset +
839841
_columnMetrics[firstColumn]!.leadingOffset +

packages/two_dimensional_scrollables/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: two_dimensional_scrollables
22
description: Widgets that scroll using the two dimensional scrolling foundation.
3-
version: 0.1.1
3+
version: 0.1.2
44
repository: https://github.com/flutter/packages/tree/main/packages/two_dimensional_scrollables
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+two_dimensional_scrollables%22+
66

packages/two_dimensional_scrollables/test/table_view/table_test.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,74 @@ void main() {
22072207
});
22082208
});
22092209
});
2210+
2211+
testWidgets(
2212+
'Merged unpinned cells following pinned cells are laid out correctly',
2213+
(WidgetTester tester) async {
2214+
final ScrollController verticalController = ScrollController();
2215+
final ScrollController horizontalController = ScrollController();
2216+
final Set<TableVicinity> mergedCell = <TableVicinity>{
2217+
const TableVicinity(row: 2, column: 2),
2218+
const TableVicinity(row: 3, column: 2),
2219+
const TableVicinity(row: 2, column: 3),
2220+
const TableVicinity(row: 3, column: 3),
2221+
};
2222+
final TableView tableView = TableView.builder(
2223+
columnCount: 10,
2224+
rowCount: 10,
2225+
columnBuilder: (_) => const TableSpan(extent: FixedTableSpanExtent(100)),
2226+
rowBuilder: (_) => const TableSpan(extent: FixedTableSpanExtent(100)),
2227+
cellBuilder: (BuildContext context, TableVicinity vicinity) {
2228+
if (mergedCell.contains(vicinity)) {
2229+
return const TableViewCell(
2230+
rowMergeStart: 2,
2231+
rowMergeSpan: 2,
2232+
columnMergeStart: 2,
2233+
columnMergeSpan: 2,
2234+
child: Text('Tile c: 2, r: 2'),
2235+
);
2236+
}
2237+
return TableViewCell(
2238+
child: Text('Tile c: ${vicinity.column}, r: ${vicinity.row}'),
2239+
);
2240+
},
2241+
pinnedRowCount: 1,
2242+
pinnedColumnCount: 1,
2243+
verticalDetails: ScrollableDetails.vertical(
2244+
controller: verticalController,
2245+
),
2246+
horizontalDetails: ScrollableDetails.horizontal(
2247+
controller: horizontalController,
2248+
),
2249+
);
2250+
await tester.pumpWidget(MaterialApp(home: tableView));
2251+
await tester.pumpAndSettle();
2252+
2253+
expect(verticalController.position.pixels, 0.0);
2254+
expect(horizontalController.position.pixels, 0.0);
2255+
expect(
2256+
tester.getRect(find.text('Tile c: 2, r: 2')),
2257+
const Rect.fromLTWH(200.0, 200.0, 200.0, 200.0),
2258+
);
2259+
2260+
verticalController.jumpTo(10.0);
2261+
await tester.pumpAndSettle();
2262+
expect(verticalController.position.pixels, 10.0);
2263+
expect(horizontalController.position.pixels, 0.0);
2264+
expect(
2265+
tester.getRect(find.text('Tile c: 2, r: 2')),
2266+
const Rect.fromLTWH(200.0, 190.0, 200.0, 200.0),
2267+
);
2268+
2269+
horizontalController.jumpTo(10.0);
2270+
await tester.pumpAndSettle();
2271+
expect(verticalController.position.pixels, 10.0);
2272+
expect(horizontalController.position.pixels, 10.0);
2273+
expect(
2274+
tester.getRect(find.text('Tile c: 2, r: 2')),
2275+
const Rect.fromLTWH(190.0, 190.0, 200.0, 200.0),
2276+
);
2277+
});
22102278
}
22112279

22122280
class _NullBuildContext implements BuildContext, TwoDimensionalChildManager {

0 commit comments

Comments
 (0)