getRepliesForComment method
- Comment comment
Returns the paging controller for a comment's replies.
Implementation
Future<PagingController<int, Comment>?> getRepliesForComment(
Comment comment) async {
PagingController<int, Comment>? pagingController =
_repliesPagingCache[comment];
if (pagingController != null) {
return pagingController;
}
CommentsList? commentsList = await _commentsClient.getReplies(comment);
pagingController = PagingController(firstPageKey: 1);
pagingController.addPageRequestListener((pageKey) async {
List<Comment> comments = [];
try {
comments.addAll(commentsList!.toList());
commentsList = await commentsList?.nextPage();
} finally {
if (comments.isEmpty) {
pagingController?.appendLastPage(comments);
} else {
pagingController?.appendPage(comments, pageKey + 1);
}
}
});
_repliesPagingCache[comment] = pagingController;
return pagingController;
}