Ganesh Sivakumar
Ganesh Sivakumar

Reputation: 147

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

Upvotes: 1

Views: 385

Answers (1)

Jahidul Islam
Jahidul Islam

Reputation: 12575

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
              })

Upvotes: 1

Related Questions