getUserPosts method

Future<List<PostModel>> getUserPosts(
  1. String userId
)

Implementation

Future<List<PostModel>> getUserPosts(String userId) async {
  final snapshot =
      await _firestore.collection('posts').where('authorId', isEqualTo: userId).get();

  return snapshot.docs.map((doc) {
    final post = PostModel.fromFirestore(doc);
    // If server sent status: "scheduled", post.status will be PostStatus.draft
    // App continues working with safe default
    return post;
  }).toList();
}