createPost method
Implementation
Future<Post> createPost(Post post) async {
final response = await http.post(
Uri.parse(url),
headers: {"Content-Type": "application/json"},
body: jsonEncode(post.toJson()),
);
if (response.statusCode == 201) {
return Post.fromJson(jsonDecode(response.body));
} else {
throw Exception("POST failed");
}
}