getProfileField method
Get the value of a profile field for a user.
userId
The user whose profile field should be returned.
keyName
The name of the profile field to retrieve.
Implementation
Future<Map<String, Object?>> getProfileField(
String userId,
String keyName,
) async {
final requestUri = Uri(
path:
'_matrix/client/v3/profile/${Uri.encodeComponent(userId)}/${Uri.encodeComponent(keyName)}',
);
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 json as Map<String, Object?>;
}