Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved Error:The operator '[]' isn't defined” error when using .data[] in flutter firestore #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

apoorvlodhi-io
Copy link

Changed this: name: doc.data['name'] ?? ''
Into this: name: doc.data()['name'] ?? ''

Firestore's data used to be a property of QueryDocumentSnapshot, but now it is a function, data().
data() is a method now therefore you have to add (), from the source code.
And, as the error message suggests, what you are dealing with is indeed a Map<String, dynamic> Function(), i.e. a function that returns a map.

So, simply add empty parentheses to call the function data:

Map<String, dynamic> data() {
return _CodecUtility.replaceDelegatesWithValueInMap(
_delegate.data(), _firestore);
}

Refer to Firestore Docs: https://github.com/FirebaseExtended/flutterfire/blob/master/packages/cloud_firestore/cloud_firestore/lib/src/document_snapshot.dart#L38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant