updatePost method

Future<Post> updatePost(
  1. int id,
  2. Post post
)

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("Failed to update post");
  }
}