error when trying to use StreamBuilder<QuerySnapshot>

126

Another point is to check if your list has items and if the firebase path is correct

Share:
126
Jorge Ribeiro
Author by

Jorge Ribeiro

Student of systems analysis and development 5th sem. Graduated in UX|UI Design. 2 years of experience in technology with knowledge in web / mobile

Updated on January 03, 2023

Comments

  • Jorge Ribeiro
    Jorge Ribeiro over 1 year

    hello people get this error when trying to use QuerySnapshot

       child: StreamBuilder<QuerySnapshot>(
                  stream:
                      FirebaseFirestore.instance.collection('messages').snapshots(),
                  builder: (context, snapshot) {
                    switch (snapshot.connectionState) {
                      case ConnectionState.none:
                      case ConnectionState.waiting:
                        // ignore: prefer_const_constructors
                        return Center(
                          // ignore: prefer_const_constructors
                          child: CircularProgressIndicator(),
                        );
                      default:
                        List<DocumentSnapshot> documents =
                            snapshot.data!.docs.reversed.toList();
                        return ListView.builder(
                            itemCount: documents.length,
                            reverse: true,
                            itemBuilder: (context, index) {
                              return ListTile(
                                title: Text(documents[index]['text']),
                              );
                            });
                    }
                  },
                ),
    

    Exception caught by widgets library The following _CastError was thrown building StreamBuilder<QuerySnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<QuerySnapshot<Object?>, AsyncSnapshot<QuerySnapshot<Object?>>>#b7dc5):Null check operator used on a null value

    • Gabriel Almeida
      Gabriel Almeida about 2 years
      Have you tried putting a breakpoint on the Title line?