data method
Retrieves all fields in the document as an object. Returns 'undefined' if the document doesn't exist.
Returns an object containing all fields in the document or 'null' if the document doesn't exist.
final documentRef = firestore.doc('col/doc');
documentRef.get().then((documentSnapshot) {
final data = documentSnapshot.data();
print('Retrieved data: ${JSON.stringify(data)}');
});
Implementation
@override
T data() {
final data = super.data();
if (data == null) {
throw StateError(
'The data in a QueryDocumentSnapshot should always exist.',
);
}
return data;
}