likePost method

  1. @override
Future<TimelinePost> likePost(
  1. String userId,
  2. TimelinePost post
)

Implementation

@override
Future<TimelinePost> likePost(String userId, TimelinePost post) async {
  var updatedPost = post.copyWith(
    likes: post.likes + 1,
    likedBy: (post.likedBy ?? [])..add(userId),
  );
  posts = posts
      .map(
        (p) => p.id == post.id ? updatedPost : p,
      )
      .toList();

  notifyListeners();
  return updatedPost;
}