getPosts method Null safety

  1. @override
Future<List<Post>> getPosts(
  1. {String? subreddit,
  2. PostSort sortBy = PostSort.hot,
  3. PostSortSince since = PostSortSince.none,
  4. String? after,
  5. int limit = 100}
)
override

Implementation

@override
Future<List<Post>> getPosts({
  String? subreddit,
  PostSort sortBy = PostSort.hot,
  PostSortSince since = PostSortSince.none,
  String? after,
  int limit = 100
}) async {
  List<UserContent> posts = await Function.apply(_getSort(subreddit)[sortBy]!, [], {
    #after: after,
    #limit: limit
  }).toList();
  return await Future.wait(posts
    .whereType<Submission>()
    .map((event) async {
      return Post(
        id: event.fullname!,
        title: HtmlUnescape().convert(event.title),
        text:  event.selftext != null
          ? HtmlUnescape().convert(event.selftext!)
          : null,
        videoUrl: event.isVideo ? event.data!["media"]["reddit_video"]["hls_url"] : null,
        imageUrl: RegExp(r".(gif|jpe?g|bmp|png)$").hasMatch(event.url.toString())
          ? event.url.toString()
          : null,
        upVotes: event.upvotes,
        downVotes: event.downvotes,
        upVotesRatio: event.upvoteRatio,
        subReddit: convertFromReddit(await event.subreddit.populate())
      );
    })
    .toList());
}