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

前端 未结 2 1830
予麋鹿
予麋鹿 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:41

    Change this:

    name: doc.data['name'] ?? '' 
    

    Into this:

    name: doc.data()['name'] ?? '' 
    

    data() is a method now therefore you have to add (), from the source code:

      Map data() {
        return _CodecUtility.replaceDelegatesWithValueInMap(
            _delegate.data(), _firestore);
      }
    

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

提交回复
热议问题