“The operator '[]' isn't defined” error when using .data[] in flutter firestore

前端 未结 2 1831
予麋鹿
予麋鹿 2020-12-06 18:00

I am learning to use firestore in flutter following Net Ninja\'s tutorial on youtube. After user authenticatin was done this guy added user records to the database whenever

2条回答
  •  一向
    一向 (楼主)
    2020-12-06 18:57

    Firestore's data used to be a property of QueryDocumentSnapshot, but now it is a function, data().

    And, as the error message suggests, what you are dealing with is indeed a Map Function(), i.e. a function that returns a map.

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

    doc.data()['name']
    

提交回复
热议问题