updateUser method

Future<User> updateUser(
  1. User userData,
  2. int userID
)

Updates the user with the given userID using the provided userData. Returns the updated user object if the API call is successful.

Implementation

Future<User> updateUser(User userData, int userID) async {
  final response = await callApi(
      endpoint: 'users/$userID', method: 'put', body: userData.toJson());

  if (response.statusCode == 200) {
    final responseData = json.decode(response.body);
    final updatedUser = User.fromJson(responseData);
    return updatedUser;
  } else {
    throw Exception(response);
  }
}