I’m using Flutter SDK to query posts from UserFeed, CommunityFeed, and Global Feed. Despite there being posts on Amity Social Cloud Console, when I query either three of them, it didn’t return any posts (I checked UserID, and CommunityID that has posts).
This is code from Amity Docs:
void queryUserFeed(String userId) {
//initiate the PagingController
_controller = PagingController(
pageFuture: (token) => AmitySocialClient.newFeedRepository()
.getUserFeed(userId)
.getPagingData(token: token, limit: 20),
pageSize: 20,
)..addListener(
() {
if (_controller.error == null) {
//handle results, we suggest to clear the previous items
//and add with the latest _controller.loadedItems
posts.clear();
posts.addAll(_controller.loadedItems);
//update widgets
} else {
//error on pagination controller
//update widgets
}
},
);
if (kDebugMode) {
print(posts.length);
}
}
Same issue for us, 0 posts in the controller. Printing has nothing to do with it. The controller itself has 0 loadedItems. Is that a timing issue? When and where to call the initPagingController?
It would be super helpful if you could put the queryUserFeed function in a broader context of an example class. Your Flutter documentation on feeds is quite limited, unfortunately.
PS: Awaiting the newFeedRepository actually returns a list of the posts. Instead of coding our own solution around this we would love to follow the officially intended way.
queryUserFeed(String userId) async {
var test = await AmitySocialClient.newFeedRepository()
.getUserFeed(userId)
.getPagingData(limit: 20);
return test;
}
Hello, based on your question, await is mandatory for this as the method will call to our system which is an asynchronous call so you will have to wait until the method successfully returns the data in order to render it on the front end side. In addition you can use this code snippet as well.
Thanks for getting back to me. Adding async await and/or .then((value) {}) to the newFeedRepository call from the documentation has no effect. Still 0 loadedItems in the _controller.