0

I tries this code but it shows me this error :Bad state: field does not exist within the DocumentSnapshotPlatform

body: Center(
        child: Container(
            padding: const EdgeInsets.all(20.0),
            child: StreamBuilder<QuerySnapshot>(
              stream: FirebaseFirestore.instance
                  .collection("users")
                  .doc(widget.uid)
                  .collection('tasks')
                  .snapshots(),
              builder: (BuildContext context,
                  AsyncSnapshot<QuerySnapshot> snapshot) {
                if (snapshot.hasError)
                  return new Text('Error: ${snapshot.error}');
                switch (snapshot.connectionState) {
                  case ConnectionState.waiting:
                    return new Text('Loading...');
                  default:
                    return new ListView(
                      children: snapshot.data.**docs**
                          .map<Widget>((DocumentSnapshot document) {
                        return new CustomCard(
                          title: document.data()['title'],
                          description: document.data()['description'],
                        );
                      }).toList(),
                    );
                }
              },
            )),
      ),strong text

help please

Qudsy
  • 1

4 Answers4

1

This error is stating it cannot find the field in cloud firestore , from what you’ve posted it looks like you are trying to grab a field from a. sub collection, you need to make sure the document Id Is correct as well as the field names for it to pull them.

londonlad
  • 11
  • 2
0

The error message is clear. It simply means that you are trying to retrieve a field that does not exist in your documents. Check the spelling of the names of your document fields and see if it's the same as in the code.

Kennedy Owusu
  • 5,690
  • 4
  • 15
  • 20
0

I solved problem: "field does not exist within the DocumentSnapshotPlatform"

by removing all "fields" in firebase (third chart).

Let`s check this solution ;)

Shosho55
  • 16
  • 1
0

I recently came across this error "Bad state: field does not exist within the DocumentSnapshotPlatform" and I was unsure of what it meant and tried fixing so many different things, and it was still showing, then finally I thought to check the fields of the Firestore documents that my Flutter query was concerned with.

I found that on most documents within the relevant collection, that the fields I was asking for were present, however, on the documents where I had set sub-collections to begin, the fields I had asked for were not present.

I thought to add the field names of the fields relevant to my Flutter query onto the documents that started sub-collections, and after doing so the error went away.

There were a few hours spent on this error - so cherish : )

mathems32
  • 115
  • 9