How to inherit scrolling from Nested Scroll View to Flutter DataTable?
In this article, we will show you how to inherit scrolling from NestedScrollView to Flutter DataTable.
Initialize the SfDataGrid with the necessary properties. The NestedScrollView enables a SliverAppBar (or other sliver widgets) to remain fixed while allowing the inner content, such as SfDataGrid, to scroll independently. To avoid conflicts with the scrolling mechanism, NeverScrollableScrollPhysics is applied to disable DataGrid’s internal scrolling, ensuring that the parent widget controls it. SliverOverlapAbsorber and SliverOverlapInjector maintain layout consistency, while SliverToBoxAdapter wraps the SfDataGrid for seamless integration within the sliver structure. Additionally, setting shrinkWrapRows to true ensures the DataGrid adjusts its height dynamically, allowing the parent widget to manage scrolling effectively.
@override
Widget build(BuildContext context) {
final List<String> tabs = ['Tab 1', 'Tab 2', 'Tab 3'];
return DefaultTabController(
length: tabs.length,
child: Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [
SliverOverlapAbsorber(
handle:
NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
title: const Text('Syncfusion Flutter DataGrid'),
floating: false,
pinned: true,
expandedHeight: 40.0,
bottom: TabBar(
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
controller: _tabController,
isScrollable: true,
tabs: const [
Tab(child: Text('1')),
Tab(child: Text('2')),
Tab(child: Text('3')),
],
),
),
),
];
},
body: TabBarView(
controller: _tabController,
children: tabs.map((String name) {
return SafeArea(
top: false,
bottom: false,
child: Builder(
builder: (BuildContext context) {
return CustomScrollView(
key: PageStorageKey<String>(name),
slivers: [
SliverOverlapInjector(
handle:
NestedScrollView.sliverOverlapAbsorberHandleFor(
context),
),
SliverPadding(
padding: const EdgeInsets.all(8.0),
sliver: SliverToBoxAdapter(
child: buildDataGrid(),
),
),
],
);
},
),
);
}).toList(),
),
),
),
);
}
You can download this example on GitHub.
Conclusion
I hope you enjoyed learning how to inherit scrolling from Nested Scroll View to Flutter DataTable.
You can refer to our Flutter DataTable feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataTable Example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!