reactToPost method

  1. @override
Future<TimelinePost> reactToPost(
  1. TimelinePost post,
  2. TimelinePostReaction reaction, {
  3. Uint8List? image,
})
override

Implementation

@override
Future<TimelinePost> reactToPost(
  TimelinePost post,
  TimelinePostReaction reaction, {
  Uint8List? image,
}) async {
  var reactionId = DateTime.now().millisecondsSinceEpoch.toString();

  var updatedReaction = reaction.copyWith(
    id: reactionId,
    creator: const TimelinePosterUserModel(
      userId: 'test_user',
      imageUrl:
          'https://cdn.britannica.com/68/143568-050-5246474F/Donkey.jpg?w=400&h=300&c=crop',
      firstName: 'Ico',
      lastName: 'Nica',
    ),
  );

  var updatedPost = post.copyWith(
    reaction: post.reaction + 1,
    reactions: post.reactions?..add(updatedReaction),
  );

  posts = posts
      .map(
        (p) => p.id == post.id ? updatedPost : p,
      )
      .toList();
  notifyListeners();
  return updatedPost;
}