getUserProfile method

Future<ProfileInformation> getUserProfile(
  1. String userId
)

Get the combined profile information for this user. This API may be used to fetch the user's own profile information or other users; either locally or on remote homeservers.

userId The user whose profile information to get.

Implementation

Future<ProfileInformation> getUserProfile(String userId) async {
  final requestUri =
      Uri(path: '_matrix/client/v3/profile/${Uri.encodeComponent(userId)}');
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  if (bearerToken != null) {
    request.headers['authorization'] = 'Bearer ${bearerToken!}';
  }
  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 ProfileInformation.fromJson(json as Map<String, Object?>);
}