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