createPost method

Future<Post> createPost(
  1. Post post
)

Implementation

Future<Post> createPost(Post post) async {
  final response = await http.post(
    Uri.parse(url),
    body: jsonEncode(post.toJson()),
  );

  if (response.statusCode == 201) {
    return Post.fromJson(jsonDecode(response.body));
  } else {
    throw Exception("Failed to create post");
  }
}