I'm doing a Flutter course and we are currently looking at Firestore/Firebase.
In the tutorial for a simple community board, the online instructor uses a version of Dart/Flutter which is a little earlier than the one I am using (I'm using the latest V1.22.6). The out put will put a title, description and timestamp on cards in a ListView
In the Firestore DB, one of the documents has a timestamp field and the other two do not. This exercise was to show how to return a null value or nothing if it doesn't exist. He fixes this by a piece of code so that it just returns nothing on the card:
Text((snapshot.documents[index].data["timestamp"] == null) ? "" :
snapshot.documents[index].data["timestamp"].toString())
With the updates to the SDK, I have fixed the syntax, but it won't print null or anything, it just falls flat with the error 'Bad state: field does not exist within the DocumentSnapshotPlatform'. I'm wondering if there's a workaround so that if there's a bunch of documents in a Firestore DB and for whatever reason a field does not exist in the document, what is the best way just to print nothing on the card?
My code with the updated syntax:
Text((snapshot.docs[index]['timestamp'] == null) ? 'N/A' :
snapshot.docs[index]['timestamp'].toString())
The error stack:
The following StateError was thrown building CustomCard(dirty):
Bad state: field does not exist within the DocumentSnapshotPlatform
#0 DocumentSnapshotPlatform.get._findKeyValueInMap
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:82
#1 DocumentSnapshotPlatform.get._findComponent
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:100
#2 DocumentSnapshotPlatform.get
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:115
#3 DocumentSnapshot.get
package:cloud_firestore/src/document_snapshot.dart:45
#4 DocumentSnapshot.[]
package:cloud_firestore/src/document_snapshot.dart:52
...
════════════════════════════════════════════════════════════════════════════════
question from:
https://stackoverflow.com/questions/66067832/flutter-bad-state-field-does-not-exist-within-the-documentsnapshotplatform 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…