skip to Main Content

I have a ListView in a CustomScrollView widget that should display some text but the problem is that it does not display anything.
if i remove the CustomScrollView widget, the problem will be solved!
But i need to use CustomScrollView
What is the problem?

             CustomScrollView(
                slivers: [
                  SliverToBoxAdapter(
                    child: Expanded(
                      child: ListView.builder(
                        itemBuilder: (context, index) {
                           return Text("${index}");
                        },
                        itemCount: 5,
                      ),
                    ),
                  )
                ],
              ),

3

Answers


  1. Try to give listview properties shrinkWrap: true and try with expanded or without expanded

    Login or Signup to reply.
  2. You could use CustomScrollView slightly differently to achieve that:

    CustomScrollView(
          slivers: [
            SliverFillRemaining(
              hasScrollBody: true,
              child: ListView.builder(
                itemBuilder: (context, index) {
                  return Text("${index}");
                },
                itemCount: 5,
              ),
            )
          ],
        )
    
    Login or Signup to reply.
  3. You should use SliverList inside CustomScrollView.

    CustomScrollView(
      slivers: [
        SliverList(
            delegate: SliverChildBuilderDelegate(
          childCount: 5,
          (context, index) {
            return Text("${index}");
          },
        )),
      ],
    ),
    

    Find more about CustomScrollView

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search