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

Time:06-10

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'

CodePudding user response:

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.

  • Related