简体   繁体   中英

'List<dynamic>' is not a subtype of type '(BuildContext, int) => Widget' flutter

I'm trying to show data from firestore firebase , but i got an error

'List' is not a subtype of type '(BuildContext, int) => Widget'

 Container (
                margin: EdgeInsets.only(bottom: 550 , right: 140),
                child: Text("Filter by Patient" , style: TextStyle(color: Colors.teal, fontSize: 17),), 
                ), 
                Expanded(
              child :  Container( //list image profile 
                 child: StreamBuilder<QuerySnapshot>(
            stream: db.collection("patient").snapshots(),
               builder: (BuildContext context, AsyncSnapshot snapshot){
                 if(snapshot.data == null){
                return Container(
                  child: Center(
                    child: Text("Loading...")
                  )
                   );
               } else{
                return   ListView.builder(
                  
                  scrollDirection: Axis.horizontal,
                  itemBuilder: snapshot.data!.docs.map<Widget>((doc) {
                    return Card(
                          child:ListTile(
                           title: new Text(doc['name']) ,
                      onTap: (){},
                    ),
                    );
                  }).toList(),
                   );
                }
            },
          ),
          ), 

I printed snapshot.data!.docs and this the result

I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot']

Another exception was thrown: type 'List' is not a subtype of type '(BuildContext, int) => Widget'

Another exception was thrown: Incorrect use of ParentDataWidget. I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot'] I/flutter ( 6015): [Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot', Instance of '_JsonQueryDocumentSnapshot']

Another exception was thrown: Incorrect use of ParentDataWidget.

Another exception was thrown: type 'List' is not a subtype of type '(BuildContext, int) => Widget'

That is not the way to use itemBuilder . You have to do something like this:

// if snapshot.data!.docs is a List
List value = snapshot.data!.docs;
return ListView.builder(
  itemBuilder(context, index){
    return Card(
      child:ListTile(
      title: Text(value[index]['name']) ,
      onTap: (){},
    ),
  }
)

Check the docs for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM