RivaanRanawat / instagram-flutter-clone

Responsive Instagram Clone developed with Flutter & Firebase
https://youtu.be/BBccK1zTgxw
858 stars 474 forks source link

Search Screen StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) #18

Closed Davepn16 closed 1 year ago

Davepn16 commented 1 year ago

If you get "StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)" on search screen at :

(snapshot.data! as dynamic).docs[index] ['photoUrl'],

you should use: if (snapshot.connectionState == ConnectionState.waiting)

instead of : if (!snapshot.hasData)

It looks like hasdata returns true for any non-null data, and [] is non-null data, hence hasdata will return true while the snapshot is still in a waiting state.

Always use ConnectionState.waiting, never use junky hasdata which actually means "not null".

RivaanRanawat commented 1 year ago

Thanks for the tip!

muhammetaydinn commented 1 year ago

image not solved open issue please @RivaanRanawat

muhammetaydinn commented 1 year ago

I think we have to check the photoUrl null or not before. solved but not sure

  backgroundImage: NetworkImage(
                                (snapshot.data! as dynamic)
                                        .docs[index]
                                        .data()["photoUrl"] ??
                                    imageUrl),
                          ),
LosPhilly commented 1 year ago

This worked for me thanks for the tip!

LosPhilly commented 1 year ago

If you get "StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)" on search screen at :

(snapshot.data! as dynamic).docs[index] ['photoUrl'],

you should use: if (snapshot.connectionState == ConnectionState.waiting)

instead of : if (!snapshot.hasData)

It looks like hasdata returns true for any non-null data, and [] is non-null data, hence hasdata will return true while the snapshot is still in a waiting state.

Always use ConnectionState.waiting, never use junky hasdata which actually means "not null".

Thanks for the tip this added to the success!