Browse SDKs · Flutter
Platform
SDKsFlutter

Retrieve specified user profiles

Retrieve application users’ public profiles (PublicUserInfo) in batches by userID.

Copy

Use getUsersInfo() to retrieve application users' public profiles by userID. It is suitable for displaying friend candidates and profile cards for users who are not friends.

To search by nickname, phone number, organization, email address, or another application field, retrieve candidate userID values from the application backend and then query their public profiles with this method.

Retrieve public profiles

final userIDList = {'user_a', 'user_b'}.toList();

try {
  final users = await OpenIM.iMManager.userManager.getUsersInfo(
    userIDList: userIDList,
  );
  final usersByID = {
    for (final user in users)
      if (user.userID != null) user.userID!: user,
  };
  showUsers(usersByID);
} catch (error) {
  logUserQueryFailure(error, userIDList);
  rethrow;
}

userIDList is a required list of OpenIMSDK user IDs. Deduplicate it and limit the size of each request before calling the API.

Result

The successful Future returns List<PublicUserInfo>:

FieldDescription
userIDOpenIMSDK user ID.
nicknameAccount-level public nickname.
faceURLAccount-level public avatar URL.
exAccount-level extension string whose format is defined by the application.

The ex returned here is read-only public extension data for other accounts. The Flutter client cannot use the User API to change another account's public profile. The current user can update their own ex through setSelfInfo(); see Update the current user's profile for the whole-value replacement behavior.

Call result and profile refresh

After the query succeeds, replace the current public-profile snapshot with the returned List<PublicUserInfo>. When a page displays several users, collect the visible userID values, deduplicate them, query them in one batch, and merge the results by userID.

This read-only query does not trigger OnUserListener. Call getUsersInfo() again to reconcile the snapshot when opening a profile card, when the user refreshes, after reconnection, or when the application backend reports a profile change.

OnUserListener.onSelfInfoUpdated contains only the current user's UserInfo; it is not an event for the public profile of any user.

Search before adding a friend

To search for and add a friend, the application backend typically returns candidate userID values first, and the client then calls getUsersInfo() to display their public profiles. After the user confirms a target, proceed to the friend-application flow.

If the application supports exact user-ID lookup, pass the entered value directly as userID. For fuzzy search by nickname, phone number, organization, email, or another application field, obtain candidate IDs from the application backend.

Choose display data by scenario

The same userID can have different display names and relationship data in different contexts. Choose the source that matches the current UI:

ScenarioPreferred type
Application user search or a non-friend profile cardPublicUserInfo
Friend list, contacts, or friend remarksFriendInfo
Group member list, in-group nickname, or group roleGroupMembersInfo

Friend remarks and in-group nicknames come from the friend relationship and group member profile, respectively. Do not overwrite them with PublicUserInfo.nickname. See Retrieve the friend list by page, Retrieve specified friend profiles, and Retrieve group members.

Next steps