6

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.

0

1 Answer 1

13

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.

  1. SliverChildBuilderDelegate - needs a builder method which will be called to build widget for each list item. It is same as ListView.builder()
  2. SliverChildListDelegate - needs a list of widget which would be the items of the SliverList. It is same as ListView(children: ...)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks alot Harsh. It solved all my problems instantly. Kudos.
vote up and mark it correct, please. shamlessly_asking!! 💐💐
I couldn't. I have less than 15 reputation... I will one day.. The solution worked. Thanks alot . 💪
@HarshBhikadia can you help me with this question. I am also facing similar issues stackoverflow.com/questions/62437049/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.