Skip to content
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

[two_dimensional_scrollables] Merged cells for TableView #5917

Merged
merged 22 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
4 changes: 4 additions & 0 deletions packages/two_dimensional_scrollables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0

* [Breaking change] Adds support for merged cells in the TableView.

## 0.0.6

* Fixes an error in TableSpanDecoration when one or both axes are reversed.
Expand Down
81 changes: 51 additions & 30 deletions packages/two_dimensional_scrollables/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ class _TableExampleState extends State<TableExample> {
late final ScrollController _verticalController = ScrollController();
int _rowCount = 20;

final Map<TableVicinity, ({int start, int span})> mergedRows =
<TableVicinity, ({int start, int span})>{
TableVicinity.zero: (start: 0, span: 2),
TableVicinity.zero.copyWith(row: 1): (start: 0, span: 2),
};

final Map<TableVicinity, ({int start, int span})> mergedColumns =
<TableVicinity, ({int start, int span})>{
const TableVicinity(row: 0, column: 1): (start: 1, span: 2),
const TableVicinity(row: 0, column: 2): (start: 1, span: 2),
};

// If a merged square is along the identity matrix, the values are the same
// for row merge and column merge data.
final Map<TableVicinity, ({int start, int span})> mergedIdentitySquares =
<TableVicinity, ({int start, int span})>{
const TableVicinity(row: 1, column: 1): (start: 1, span: 2),
const TableVicinity(row: 1, column: 2): (start: 1, span: 2),
const TableVicinity(row: 2, column: 1): (start: 1, span: 2),
const TableVicinity(row: 2, column: 2): (start: 1, span: 2),
};

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -53,44 +75,43 @@ class _TableExampleState extends State<TableExample> {
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: TableView.builder(
verticalDetails:
ScrollableDetails.vertical(controller: _verticalController),
verticalDetails: ScrollableDetails.vertical(
controller: _verticalController,
),
cellBuilder: _buildCell,
columnCount: 20,
columnBuilder: _buildColumnSpan,
rowCount: _rowCount,
columnBuilder: _buildColumnSpan,
rowBuilder: _buildRowSpan,
),
),
persistentFooterButtons: <Widget>[
TextButton(
onPressed: () {
_verticalController.jumpTo(0);
},
child: const Text('Jump to Top'),
),
TextButton(
onPressed: () {
_verticalController
.jumpTo(_verticalController.position.maxScrollExtent);
},
child: const Text('Jump to Bottom'),
),
TextButton(
onPressed: () {
setState(() {
_rowCount += 10;
});
},
child: const Text('Add 10 Rows'),
),
],
);
}

Widget _buildCell(BuildContext context, TableVicinity vicinity) {
return Center(
child: Text('Tile c: ${vicinity.column}, r: ${vicinity.row}'),
TableViewCell _buildCell(BuildContext context, TableVicinity vicinity) {
final bool mergedCell = mergedRows.keys.contains(vicinity) ||
mergedColumns.keys.contains(vicinity) ||
mergedIdentitySquares.keys.contains(vicinity);
if (mergedCell) {
return TableViewCell(
rowMergeStart: mergedIdentitySquares[vicinity]?.start ??
mergedRows[vicinity]?.start,
rowMergeSpan:
mergedIdentitySquares[vicinity]?.span ?? mergedRows[vicinity]?.span,
columnMergeStart: mergedIdentitySquares[vicinity]?.start ??
mergedColumns[vicinity]?.start,
columnMergeSpan: mergedIdentitySquares[vicinity]?.span ??
mergedColumns[vicinity]?.span,
child: const Center(
child: Text('Merged'),
),
);
}

return TableViewCell(
child: Center(
child: Text('(${vicinity.row}, ${vicinity.column})'),
),
);
}

Expand Down Expand Up @@ -148,7 +169,7 @@ class _TableExampleState extends State<TableExample> {

TableSpan _buildRowSpan(int index) {
final TableSpanDecoration decoration = TableSpanDecoration(
color: index.isEven ? Colors.purple[100] : null,
color: index.isEven ? Colors.blueAccent[100] : null,
border: const TableSpanBorder(
trailing: BorderSide(
width: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading