Home > Back-end >  Failure to display anything in ListViewBuilder
Failure to display anything in ListViewBuilder

Time:01-10

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,
                      ),
                    ),
                  )
                ],
              ),

CodePudding user response:

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

CodePudding user response:

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,
          ),
        )
      ],
    )

CodePudding user response:

You should use SliverList inside CustomScrollView.

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

Find more about CustomScrollView

  • Related