What is the preferred way to achieve a nested ListView, or in other words, ListView Widgets that could be included within a scrollable parent?
Imagine a "Reports" page, where a section is an itemized list.
If you want to have the inner ListView be scrollable independently of the main scroll view, you should use NestedScrollView . Otherwise, use a CustomScrollView . Here is some code illustrating the NestedScrollView approach. The "main" scroll, the Nested, does not scroll at all.
separated. In Flutter, you can use ListView. separated to easily create a list view whose items are separated by separators (or dividers). A separator only appears between two list items and never stands before the first or sits after the last item.
For child ListView, use that parameter:
shrinkWrap: true, physics: ClampingScrollPhysics(),
Adding physics: ClampingScrollPhysics()
and shrinkWrap: true
did the trick for me.
sample code:
@override Widget build(BuildContext context) { return Container( child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ Expanded( child: ListView.builder( shrinkWrap: true, itemCount: 123, itemBuilder: (BuildContext context, int index) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ Text('Parent'), ListView.builder( itemCount: 2, physics: ClampingScrollPhysics(), shrinkWrap: true, itemBuilder: (BuildContext context, int index) { return Text('Child'); }), ], ); }), ) ], ), ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With