How can I build two lists to be displayed vertically so as one list of item is built and then the second follows in that vertical order.
1 Answer
You can achieve this by using CustomScrollView with SliverList.
Your solution would look something like this:
CustomScrollView(
slivers: <Widget>[
//list 1 (using builder)
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) {
return ListTile(...); // HERE goes your list item
},
childCount: 3,
),
),
//list 2 (using list of widgets)
SliverList(
delegate: SliverChildListDelegate([
ListTile(..),
ListTile(..), //HERE goes your list item
]),
),
],
),
this will build one list after another as you scroll down. in the example above i have used both types of delegates available to build list.
- SliverChildBuilderDelegate - needs a builder method which will be called to build widget for each list item. It is same as
ListView.builder() - SliverChildListDelegate - needs a list of widget which would be the items of the SliverList. It is same as
ListView(children: ...)
4 Comments
kelvin
Thanks alot Harsh. It solved all my problems instantly. Kudos.
Harsh Bhikadia
vote up and mark it correct, please. shamlessly_asking!! 💐💐
kelvin
I couldn't. I have less than 15 reputation... I will one day.. The solution worked. Thanks alot . 💪
Roxx
@HarshBhikadia can you help me with this question. I am also facing similar issues stackoverflow.com/questions/62437049/…