Get friend list with pagination
Retrieve the current user friend list using pagination in the OpenIM Flutter SDK.
Retrieve the currently logged-in user's friend list using pagination:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
offset | int | Yes | Pagination offset index. Start at 0 for the first page. |
count | int | Yes | Maximum number of friend records to fetch per page. |
filterBlack | bool | No | Whether to exclude friends present on the blocklist. Pass true to filter out blocked users; pass false to include them. |
Code example
final friends = await OpenIM.iMManager.friendshipManager.getFriendListPage(
offset: 0,
count: 40,
filterBlack: true,
);Return value
A successful Future returns a list of friend profiles for the requested page (List<FriendInfo>).
The client should deduplicate and append items to the local contacts list using userID as the primary key. When the returned list length is less than count, the end of the friend list has been reached.
Always use paginated queries to retrieve friend data to avoid performance overhead on large contact rosters. This query returns a local database snapshot and does not emit friendship events.
Listen for friend change events
Friend additions, profile modifications, and deletions are handled centrally through listener callbacks. In your contact state store, use userID as the sole key for merging, updating, or deleting friend entries:
void handleFriendChanged(FriendInfo info) {
mergeFriend(info);
}
void handleFriendDeleted(FriendInfo info) {
final userID = info.userID;
if (userID != null) removeFriend(userID);
}The Flutter SDK maintains a single OnFriendshipListener instance inside FriendshipManager. Integrate these handler functions into your application's contact store and register the listener centrally (see Events overview) rather than setting listeners inside individual Widget trees.
Was this page helpful?