I’m getting this error:
Bad state: field does not exist within the DocumentSnapshotPlatform
with the following code:
static List<Report?> reportListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.docs.map<Report?>((report) {
return Report(
type: report['type'],
reason: report['reason'],
reportId: report['id'],
chat:
(report['chat'] == null) ? null : Chat.chatFromMap(report['chat']),
stingray: Stingray.stingrayFromDynamic(report['stingray']),
reporterUser: User.fromDynamic(report['reporterUser']),
reportTime: report['reportTime'].toDate(),
);
}).toList();
}
Its failing on the first map,
type: report['type'],
and when i look at it in debug mode, it shows the data i am looking for:
As you can see from the screenshot, ‘type’ exists with a value of ‘chat report’. Any idea why this is breaking?
Thanks!
3
Answers
The problem turned out to be larger in scope than i thought. I was uploading a map object to firebase rather than just a document, and that map was attempting to be read, which is where the error occurred due to it only having one value in the document snapshot.
You are supposed to call .data() on
report
Check out this link on how to use
withConverter
so you do not have to manually convert models.Maybe you have typo in your field which does not match with your model fields. So the idea is that, your fields in your model has to match with the fields in your firebase snapshot fields.
enter link description here