Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter, The element type 'List<ListTile>' can't be assigned to the list type 'Widget'

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();
                 ],
                );
              })

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
              })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading