{"id":12733,"date":"2025-07-14T05:54:57","date_gmt":"2025-07-14T05:54:57","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=12733"},"modified":"2025-07-14T05:59:35","modified_gmt":"2025-07-14T05:59:35","slug":"nested-listview-in-flutter","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/flutter\/nested-listview-in-flutter","title":{"rendered":"How to implement Nested ListView in Flutter?"},"content":{"rendered":"<h2>Approach &#8211; 1<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\">\r\nimport 'package:flutter\/material.dart';\r\n\r\nvoid main() {\r\n runApp(const MyApp());\r\n}\r\n\r\nclass MyApp extends StatelessWidget {\r\n const MyApp({super.key});\r\n\r\n @override\r\n Widget build(BuildContext context) {\r\n   return MaterialApp(\r\n     theme: ThemeData(\r\n       colorScheme: ColorScheme.fromSeed(\r\n         seedColor: Colors.deepPurple,\r\n       ),\r\n       useMaterial3: true,\r\n     ),\r\n     home: const NestedListView(),\r\n   );\r\n }\r\n}\r\n\r\nclass NestedListView extends StatelessWidget {\r\n const NestedListView({super.key});\r\n\r\n @override\r\n Widget build(BuildContext context) {\r\n   return Scaffold(\r\n     body: SafeArea(\r\n       child: ListView.builder(\r\n         itemCount: 10,\r\n         itemBuilder: (context, index) {\r\n           return Column(\r\n             crossAxisAlignment: CrossAxisAlignment.start,\r\n             children: [\r\n               Padding(\r\n                 padding: const EdgeInsets.all(8.0),\r\n                 child: Text(\r\n                   'Category $index',\r\n                   style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),\r\n                 ),\r\n               ),\r\n               SizedBox(\r\n                 height: 100,\r\n                 child: ListView.builder(\r\n                   scrollDirection: Axis.horizontal,\r\n                   physics: ClampingScrollPhysics(),\r\n                   itemCount: 15,\r\n                   itemBuilder: (context, innerIndex) {\r\n                     return Container(\r\n                       width: 100,\r\n                       margin: EdgeInsets.all(8),\r\n                       color: Colors.blueAccent,\r\n                       child: Center(\r\n                         child: Text(\r\n                           'Item $innerIndex',\r\n                           style: TextStyle(color: Colors.white),\r\n                         ),\r\n                       ),\r\n                     );\r\n                   },\r\n                 ),\r\n               ),\r\n             ],\r\n           );\r\n         },\r\n       ),\r\n     ),\r\n   );\r\n }\r\n}\r\n<\/pre>\n<h3>Outer ListView:<\/h3>\n<p>The outer ListView.builder creates a vertically scrollable list.<br \/>\nEach item in this list contains a category title and an inner ListView.<\/p>\n<h3>Inner ListView:<\/h3>\n<p>The inner ListView.builder is configured to scroll horizontally (scrollDirection: Axis.horizontal).<br \/>\n<strong>physics: <\/strong>ClampingScrollPhysics() ensures smooth scrolling behavior.<\/p>\n<p>A fixed height (SizedBox(height: 100)) is set to constrain the inner ListView\u2019s size, preventing layout issues.<\/p>\n<h3>Scroll Conflict Resolution:<\/h3>\n<p>By default, nested scrollable widgets cause conflicts. Setting physics: NeverScrollableScrollPhysics() on the inner ListView (if vertical) or using ClampingScrollPhysics() (for horizontal) ensures the outer ListView handles primary scrolling.<\/p>\n<p><strong>shrinkWrap:<\/strong> true ensures the inner ListView takes only the space it needs.<\/p>\n<h3>Performance:<\/h3>\n<p>Using ListView.builder for both outer and inner lists ensures lazy loading, improving performance for large datasets.<br \/>\n<img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1-138x300.png\" alt=\"perform-1\" width=\"138\" height=\"300\" class=\"alignleft size-medium wp-image-12735\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1-138x300.png 138w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1-473x1024.png 473w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1-768x1664.png 768w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1-709x1536.png 709w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050657\/perform-1.png 945w\" sizes=\"(max-width: 138px) 100vw, 138px\" \/><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2-138x300.png\" alt=\"perfom-2\" width=\"138\" height=\"300\" class=\"alignright size-medium wp-image-12736\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2-138x300.png 138w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2-473x1024.png 473w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2-768x1664.png 768w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2-709x1536.png 709w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14050700\/perfom-2.png 945w\" sizes=\"(max-width: 138px) 100vw, 138px\" \/><\/p>\n<h2>Approach &#8211; 2<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"kotlin\">\r\nimport 'package:flutter\/material.dart';\r\n\r\nvoid main() {\r\n runApp(const MyApp());\r\n}\r\n\r\nclass MyApp extends StatelessWidget {\r\n const MyApp({super.key});\r\n\r\n @override\r\n Widget build(BuildContext context) {\r\n   return MaterialApp(\r\n     theme: ThemeData(\r\n       colorScheme: ColorScheme.fromSeed(\r\n         seedColor: Colors.deepPurple,\r\n       ),\r\n       useMaterial3: true,\r\n     ),\r\n     home: const NestedListView(),\r\n   );\r\n }\r\n}\r\n\r\nclass NestedListView extends StatelessWidget {\r\n const NestedListView({super.key});\r\n\r\n @override\r\n Widget build(BuildContext context) {\r\n   return Scaffold(\r\n     body: SafeArea(\r\n       child: CustomScrollView(\r\n         slivers: [\r\n           SliverList(\r\n             delegate: SliverChildBuilderDelegate(\r\n               (context, index) {\r\n                 return Column(\r\n                   crossAxisAlignment: CrossAxisAlignment.start,\r\n                   children: [\r\n                     Padding(\r\n                       padding: const EdgeInsets.all(8.0),\r\n                       child: Text(\r\n                         'Category $index',\r\n                         style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),\r\n                       ),\r\n                     ),\r\n                     SizedBox(\r\n                       height: 100,\r\n                       child: ListView.builder(\r\n                         scrollDirection: Axis.horizontal,\r\n                         physics: ClampingScrollPhysics(),\r\n                         itemCount: 15,\r\n                         itemBuilder: (context, innerIndex) {\r\n                           return Container(\r\n                             width: 100,\r\n                             margin: EdgeInsets.all(8),\r\n                             color: Colors.redAccent,\r\n                             child: Center(\r\n                               child: Text(\r\n                                 'Item $innerIndex',\r\n                                 style: TextStyle(color: Colors.white),\r\n                               ),\r\n                             ),\r\n                           );\r\n                         },\r\n                       ),\r\n                     ),\r\n                   ],\r\n                 );\r\n               },\r\n               childCount: 10,\r\n             ),\r\n           ),\r\n         ],\r\n       ),\r\n     ),\r\n   );\r\n }\r\n}\r\n<\/pre>\n<h3>Fixed Height for Inner ListView:<\/h3>\n<p>Always constrain the inner ListView\u2019s height (if vertical) or width (if horizontal) using a SizedBox or Container to avoid layout errors.<\/p>\n<h3>Scroll Physics:<\/h3>\n<p>Use NeverScrollableScrollPhysics() for inner ListView if you want the outer ListView to handle all scrolling.<br \/>\nUse ClampingScrollPhysics() for smoother scrolling in horizontal lists.<\/p>\n<h3>Performance Optimization:<\/h3>\n<p>Use ListView.builder instead of ListView to lazily load items.<\/p>\n<p>Avoid deeply nested widgets; consider CustomScrollView for complex layouts.<\/p>\n<h3>Debugging Scroll Issues:<\/h3>\n<p>If scrolling doesn\u2019t work as expected, check for conflicting physics or missing size constraints.<br \/>\nUse Flutter\u2019s DevTools to inspect the widget tree and layout<br \/>\n<img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1-138x300.png\" alt=\"scroll-output-1\" width=\"138\" height=\"300\" class=\"alignleft size-medium wp-image-12739\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1-138x300.png 138w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1-473x1024.png 473w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1-768x1664.png 768w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1-709x1536.png 709w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055412\/scroll-output-1.png 945w\" sizes=\"(max-width: 138px) 100vw, 138px\" \/><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2-138x300.png\" alt=\"scroll-output-2\" width=\"138\" height=\"300\" class=\"alignright size-medium wp-image-12740\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2-138x300.png 138w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2-473x1024.png 473w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2-768x1664.png 768w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2-709x1536.png 709w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/14055419\/scroll-output-2.png 945w\" sizes=\"(max-width: 138px) 100vw, 138px\" \/><\/p>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/best-flutter-libraries-tools-packages-and-plugins\" target=\"_blank\">Best Flutter Libraries<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Approach &#8211; 1 import &#8216;package:flutter\/material.dart&#8217;; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.deepPurple, ), useMaterial3: true, ), home: const NestedListView(), ); } } class NestedListView extends StatelessWidget { const NestedListView({super.key}); @override Widget build(BuildContext context) { return Scaffold( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12734,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-12733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12733"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=12733"}],"version-history":[{"count":5,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12733\/revisions"}],"predecessor-version":[{"id":12743,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12733\/revisions\/12743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/12734"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=12733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=12733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=12733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}