createPost method

  1. @override
Future<TimelinePost> createPost(
  1. TimelinePost post
)

Implementation

@override
Future<TimelinePost> createPost(TimelinePost post) async {
  var postId = const Uuid().v4();
  var user = await _userService.getUser(post.creatorId);
  var updatedPost = post.copyWith(id: postId, creator: user);
  if (post.image != null) {
    var imageRef =
        _storage.ref().child('${_options.timelineCollectionName}/$postId');
    var result = await imageRef.putData(post.image!);
    var imageUrl = await result.ref.getDownloadURL();
    updatedPost = updatedPost.copyWith(imageUrl: imageUrl);
  }
  var postRef =
      _db.collection(_options.timelineCollectionName).doc(updatedPost.id);
  await postRef.set(updatedPost.toJson());
  posts.add(updatedPost);
  notifyListeners();
  return updatedPost;
}