Home > Back-end >  Flutter, The element type 'List<ListTile>' can't be assigned to the list type &
Flutter, The element type 'List<ListTile>' can't be assigned to the list type &

Time:05-25

I tried geting data from firebase and display it using streamBuilder but I get this error, how do I solve it.

          body: 
          StreamBuilder<QuerySnapshot>(
              stream: firestore.collection('paymnet data').snapshots(),
              builder: (context, snapshot) {
                return ListView(
                 children: [
                   snapshot.data!.docs.map((DocumentSnapshot document){
                     Map<String,dynamic> data = document.data()! as Map<String, dynamic>;
                     return ListTile(
                       title: Text(data['amount']),
                       subtitle: Text(data['paid date']),
                     );
                   }).toList();
                 ],
                );
              })

CodePudding user response:

Just remove [] from listView children

 body: 
          StreamBuilder<QuerySnapshot>(
              stream: firestore.collection('paymnet data').snapshots(),
              builder: (context, snapshot) {
                return snapshot.hasData?ListView(
                 children:
                   snapshot.data!.docs.map((DocumentSnapshot document){
                     Map<String,dynamic> data = document.data()! as Map<String, dynamic>;
                     return ListTile(
                       title: Text(data['amount']),
                       subtitle: Text(data['paid date']),
                     );
                   }).toList();
                 
                ):Container();// or add circular progress bar
              })
  • Related