// getActivityFeed() function
class _ActivityFeedState extends State<ActivityFeed> {
Future<List<ActivityFeedItem>> getActivityFeed() async {
QuerySnapshot snapshot = await activityFeedRef
.doc(currentUser.id)
.collection('feedItems')
.orderBy('timestamp', descending: true)
.limit(50)
.get();
print(snapshot.docs);
snapshot.docs.forEach((doc) {
print(doc.data());
List<ActivityFeedItem> feedItems = [];
feedItems.add(ActivityFeedItem.fromDocument(doc));
print(feedItems);
// print('Activity Feed Item: ${doc.data}');
});
print("feed2: $feedItems");
return feedItems;
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: header(context, titleText: "Activity Feed"),
body: Container(
child: FutureBuilder(
future: getActivityFeed(),
builder: (context, snapshot) {
print("hey$feedItems");
if (!snapshot.hasData) {
return circularProgress();
}
return ListView(
children: snapshot.data,
);
},
)),
);
}
}
//FutureBuilder
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: header(context,
titleText: "Activity Feed",
),
body: Container(
child: FutureBuilder(
future: getActivityFeed(),
builder: (context, snapshot) {
print("hey$feedItems");
if (!snapshot.hasData) {
return circularProgress();
}
return ListView(
children: snapshot.data,
);
},
),
),
);
}
}
I am not getting snapshot data.... the snapshot data is null and the future builder is returning me the circularProgess()..... I have defined the function getActivityFeed which is a future. I can see in debug console that there is snapshot data and can see snapshot.doc data in console but somehow the code after print(doc.data()) is not executed and print(feedItems) I can't see it in console. What I am doing wrong in the code?