0

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,
                      ),
                    ),
                  )
                ],
              ),
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

3 Answers3

1

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

CCP
  • 886
  • 1
  • 10
  • 30
1

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,
          ),
        )
      ],
    )
Subash
  • 593
  • 3
  • 10
0

You should use SliverList inside CustomScrollView.

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

Find more about CustomScrollView

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56