setAvatarUrl method

Future<void> setAvatarUrl(
  1. String userId,
  2. Uri? avatarUrl
)
inherited

This API sets the given user's avatar URL. You must have permission to set this user's avatar URL, e.g. you need to have their access_token.

userId The user whose avatar URL to set.

avatarUrl The new avatar URL for this user.

Implementation

Future<void> setAvatarUrl(String userId, Uri? avatarUrl) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/profile/${Uri.encodeComponent(userId)}/avatar_url');
  final request = Request('PUT', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (avatarUrl != null) 'avatar_url': avatarUrl.toString(),
  }));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return ignore(json);
}