'argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Widget>'
I'm trying to retrieve data using json map and firestore but getting "The argument type 'List' can't be assigned to the parameter type 'List'" error on this line
posts.map(buildPost).toList(),
body
StreamBuilder<List<Post>>(
stream: readPost(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Text('somthing went wrong');
} else if (snapshot.hasData) {
final posts = snapshot.data;
return ListView(
children: posts.map(buildPost).toList(),
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
),
readPost Method
Stream<List<Post>> readPost() => FirebaseFirestore.instance
.collection('Posts')
.snapshots()
.map((snapshot) =>
snapshot.docs.map((doc) => Post.fromJson(doc.data())).toList());
buildPost method
buildPost(Post post) => ListTile(
leading: const Icon(Icons.account_circle_outlined),
title: Text(post.title),
subtitle: Text(post.subject),
);
Solution 1:[1]
You need to change your function
buildPost(Post post) => ListTile()
to
Widget buildPost(Post post) => ListTile()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | manhtuan21 |
