How to use StreamBuilder inside CustomScrollWidget?


I’m trying to show some data from sqlite and everything is ok but I can’t use StreamBuilder inside CustomScrollView it says:

A RenderViewport expected a child of type RenderSliver but received a child of type

Then I wrapped StreamBuilder with SliverPadding (normally SliverPadding was wrapped by StreamBuilder) but this time it says:

A RenderSliverPadding expected a child of type RenderSliver but received a child of type

I tried to use SliverToBoxAdapter and wrapped StreamBuilder with this but didn’t solve my problem so How can I achieve this?

Here is last status of my code:

  slivers: <Widget>[
      centerTitle: true,
      floating: false,
      snap: false,
      pinned: false,
      expandedHeight: 0,
      elevation: 3,
      forceElevated: true,
      backgroundColor: Theme.of(context).scaffoldBackgroundColor,
      brightness: Brightness.light,
      title: Text(
        'Your Lists',
        style: GoogleFonts.openSans(
            fontSize: 22, fontWeight: FontWeight.bold, color:,
      padding: EdgeInsets.fromLTRB(16, 16, 16, 74),
      sliver: StreamBuilder<List<Category>>(
          stream: bloc.getAll().asStream(),
          builder: (context, AsyncSnapshot<List<Category>> snapshot) {
            if (snapshot.hasData) {
              return SliverGrid(
                delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                  if (index == {
                    return ListAddCard();
                  return ListCard(
                }, childCount: + 1),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    mainAxisSpacing: 16,
                    crossAxisSpacing: 16,
                    childAspectRatio: 1.1),
            return Center(child: CircularProgressIndicator());


The solution to this is that you should wrap your entire CustomScrollView inside the Streambuilder rather than the other way round. I was facing the same issue till I used this strategy.

Answered By – Aurangzaib Ahmed Siddiqui

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *