Closure call with mismatched arguments: function '[]' in flutter

前端 未结 3 845
甜味超标
甜味超标 2021-01-25 12:12

** I am getting this error**

Closure call with mismatched arguments: function \'[]\'
Receiver: Closure: (dynamic) => dynamic from Function \'get\':.
Tried call         


        
3条回答
  •  有刺的猬
    2021-01-25 12:39

    You need to do the following:

    itemCount : snapshort.data.docs.length ,
    itemBuilder : (context,index){ 
      return QuizTile(url:snapshort.data.docs[index].data()['url'],
          title:snapshort.data.docs[index].data()['title'] ,
          desc: snapshort.data.docs[index].data()['desc'],
       );
      }
    );
    

    Since you are reference a collection, then you need to use docs which will retrieve a list of documents inside that collection:

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

    Then to access each field in the document, you need to call data()

提交回复
热议问题