Why is sliverlist not working in my customscrollview?

915
  1. Remove the const keyword of the CustomScrollView.

  2. Replace SliverChildBuilderDelegate((context) {}) with:

SliverChildBuilderDelegate((context, index) {})

Full code:

@override
Widget build(BuildContext context) {
return Scaffold(
  body: CustomScrollView(
    slivers: <Widget>[
      SliverAppBar(
        title: Text('Sample Slivers'),
        leading: Icon(Icons.menu),
        backgroundColor: Colors.orangeAccent,
        expandedHeight: 90.0,
        floating: true,
        pinned: true,
        snap: false,
      ),
      SliverList(
        delegate: SliverChildBuilderDelegate((context, index) {}),
      )
    ],
  ),
  bottomNavigationBar: _navigatorAppBar(),
  floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  floatingActionButton: _buildFab(),
);
}
Share:
915
Deyvi Tabora
Author by

Deyvi Tabora

Updated on December 23, 2022

Comments

  • Deyvi Tabora
    Deyvi Tabora over 1 year

    I am trying to add a sliverlist but it does not work for me, I am very new to using flutter and I am confused.

    @override
    Widget build(BuildContext context) {
    return Scaffold(
      body: const CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('Sample Slivers'),
            leading: Icon(Icons.menu),
            backgroundColor: Colors.orangeAccent,
            expandedHeight: 90.0,
            floating: true,
            pinned: true,
            snap: false,
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate((context) {}),
          )
        ],
      ),
      bottomNavigationBar: _navigatorAppBar(),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: _buildFab(),
    );
    }
    }
    

    img