Failed assertion: line 1702 pos 12: 'center!.parent == this': is not true

219

According to this comment in a Github thread for a similar issue if the sliver being replaced is not the first it should work fine.

So a possible workaround is to add empty SliverToBoxAdapter() as first sliver before BodyContent().

There is more information and possible solutions in the Github thread, I recommend taking a look at it.

Share:
219
Semih Yılmaz
Author by

Semih Yılmaz

Updated on January 01, 2023

Comments

  • Semih Yılmaz
    Semih Yılmaz over 1 year

    What is the reason for getting the error?

    And when I put the debug flag in the Streambuilder line, my application freezes before it comes to the main screen.

    body: CustomScrollView(
            slivers: [
              StreamBuilder<QuerySnapshot>(
                stream: FirebaseFirestore.instance
                    .collection('posts')
                    .limit(10)
                    .orderBy('id', descending: true)
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> dataSnapshot) {
                  return !dataSnapshot.hasData
                      ? SliverToBoxAdapter(
                          child: linearProgress(),
                        )
                      : SliverStaggeredGrid.countBuilder(
                          crossAxisCount: 1,
                          staggeredTileBuilder: (val) => StaggeredTile.fit(1),
                          itemBuilder: (context, index) {
                            DataModel model = DataModel.fromJson(
                                dataSnapshot.data!.docs[index].data()
                                    as Map<String, dynamic>);
                            return sourceInfo(model, context);
                          },
                          itemCount: dataSnapshot.data!.docs.length);
                },
              ),
            ],
          ),
    

    There was no problem when I imported the relevant codes into SliverPadding. Edited code.

    StreamBuilder<QuerySnapshot>(
                stream: FirebaseFirestore.instance
                    .collection('posts')
                    .limit(10)
                    .orderBy('id', descending: true)
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> dataSnapshot) {
                  return !dataSnapshot.hasData
                      ? SliverPadding(
                    sliver: SliverToBoxAdapter(
                      child: ColorLoader(),
                    ),
                    padding: EdgeInsets.all(0),
                  )
                      : SliverPadding(
                    sliver: SliverStaggeredGrid.countBuilder(
                        crossAxisCount: 1,
                        staggeredTileBuilder: (_) => StaggeredTile.fit(1),
                        itemBuilder: (context, index) {
                          DataModel model = DataModel.fromJson(
                              dataSnapshot.data!.docs[index].data()
                              as Map<String, dynamic>);
                          return sourceInfo(model, context);
                        },
                        itemCount: dataSnapshot.data!.docs.length),
                    padding: EdgeInsets.all(0),
                  );
                },
              ),