Repository navigation
Closed
flutter/packages
#11418Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: two_dimensional_scrollablesIssues pertaining to the two_dimensional_scrollables packageIssues pertaining to the two_dimensional_scrollables packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flightA fix is in flight
Description
Use case
I am currently developing a new feature in my business app using two_dimensional_scrollables package (v0.3.6). It works great for almost all the features and requirements I need. However, I have found an issue related to merged cells.
For example, my table has merged cells spanning 5 or 6 columns (these are not pinned columns). When I scroll the table horizontally and the first cell of the merged group becomes overlaid by a pinned column, it unmerges all the remaining cells. This is not the behavior I expected.
Can you help me with any ideas to avoid this issue?
Proposal
As described in my use case above, I want merged cells to remain intact (not "broken") when overlaid by pinned columns. Below is my sample code:
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:two_dimensional_scrollables/two_dimensional_scrollables.dart';
/// The class demonstrating merged cells in TableView.
class MergedTableExample extends StatefulWidget {
/// Creates a screen that shows a color palette in the TableView widget.
const MergedTableExample({super.key});
@override
State<MergedTableExample> createState() => _MergedTableExampleState();
}
class _MergedTableExampleState extends State<MergedTableExample> {
@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.sizeOf(context);
return Scaffold(
body: Padding(
padding: EdgeInsets.symmetric(horizontal: screenSize.width * 0),
child: TableView.builder(
cellBuilder: _buildCell,
columnCount: 1000,
pinnedColumnCount: 1,
columnBuilder: _buildColumnSpan,
rowCount: 51,
rowBuilder: _buildRowSpan,
),
),
);
}
TableViewCell _buildCell(BuildContext context, TableVicinity vicinity) {
final int colorIndex = (vicinity.row / 3).floor();
final TextStyle style = TextStyle(
color: Colors.black,
fontSize: 18.0,
fontWeight: vicinity.column == 0 ? FontWeight.bold : null,
);
return TableViewCell(
rowMergeStart: vicinity.column == 0 ? colorIndex * 3 : null,
rowMergeSpan: vicinity.column == 0 ? 3 : null,
columnMergeStart: vicinity.column == 1 ? vicinity.column : null,
columnMergeSpan: vicinity.column == 1 ? 3 : null,
child: ColoredBox(
color: Colors.grey,
child: Center(child: Text('cell.name', style: style)),
),
);
}
TableSpan _buildColumnSpan(int index) {
return TableSpan(
extent: FixedTableSpanExtent(index == 0 ? 220 : 50),
foregroundDecoration: index == 0
? const TableSpanDecoration(
border: TableSpanBorder(
trailing: BorderSide(width: 5, color: Colors.white),
),
)
: null,
);
}
TableSpan _buildRowSpan(int index) {
return TableSpan(
extent: const FixedTableSpanExtent(120),
padding: index % 3 == 0 ? const TableSpanPadding(leading: 5.0) : null,
);
}
}
Reacted by NguyenHuuTuan
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: two_dimensional_scrollablesIssues pertaining to the two_dimensional_scrollables packageIssues pertaining to the two_dimensional_scrollables packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flightA fix is in flight
Activity
Piinks commentedon Apr 2, 2026
I think this issue was fixed. Merged cells in the table scroll under pinned cells cleanly, the is no braking of the merging of the cell in response to lazy loading or pinning.
Runnable sample (same as above, just made it runnable):
And behavior demo:
Screen.Recording.2026-04-01.at.7.12.02.PM.mov
Piinks commentedon Apr 2, 2026
Actually, I found an edge case. If I change the cahceExtent to 0 I can trigger this. Sending a fix
Piinks commentedon Apr 2, 2026
Hi @xiabui! After taking a look, the behavior you're seeing happens because of how
TableViewlazily builds its cells. To optimize performance, the table only builds the cells currently visible in the viewport (and those within thecacheExtent).In your
_buildCellmethod, you are only providing merge information when thevicinity.columnis exactly1:When you scroll so that column 1 is no longer being built (e.g., it's behind a pinned column or off-screen), the table starts building at column 2. Since column 2 doesn't return any merge information, the table treats it as a standard, unmerged cell, causing the "unmerge" effect you're seeing. This is not the intended use of the API.
The Fix
To ensure merged cells remain intact, you must return the same child and the same merge information for every vicinity that is part of the merge.
Here is an updated version of your
_buildCellthat correctly handles the merge for columns 1, 2, and 3:I am putting up a small fix to make this more resilient when cells are hidden specifically by pinned rows or columns, and I'm updating the documentation to make the API requirement clearer.
[two_dimensional_scrollables] Fix merged cells unmerging behind pinne…
github-actions commentedon Apr 16, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[two_dimensional_scrollables] Fix merged cells unmerging behind pinne…