please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Flutter/
Local Search/
SDK
  • Install Chat SDK
    • Install
  • Initialize Chat SDK
    • Initialize
  • Login And Logout
    • Login and Logout
  • Message
    • Message Overview
    • Sending Message
    • Receiving Message
    • Historical Message
    • Forwarding Message
    • Modifying Message
    • Message Inserting
    • Deleting Message
    • Clearing Messages
    • Recalling Message
    • Online Message
    • Read Receipt
    • Querying Message
    • Group @ Message
    • Targeted Group Message
    • Notification Muting
    • Message Extension
  • Conversation
    • Conversation Overview
    • Conversation List
    • Getting Conversation
    • Conversation Unread Count
    • Pinning Conversation to the Top
    • Deleting Conversation
    • Conversation Draft
    • Conversation Group
  • Group
    • Group Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
  • User
    • User Profile
    • Friend Management
    • Friend List
    • Blocklist
  • Offline Push
    • Offline Push
  • Signaling
    • Signaling Management
  • Local Search
    • Searching for Message
    • Searching for Friend
    • Searching Group
    • Searching for Group Member
  • API Reference
    • Client APIs
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Searching for Friend

Overview

Only locally stored users can be searched for, such as contacts or user profiles that have been pulled.
Note:
This feature is supported by the SDK for Flutter v3.8.0 or later.

Searching for the Local User Profile

Call the searchFriends API (details) to search for the local user profile. You can set the search keyword keywordList and specify the search scope to set whether to search by the userID, nickName, and remark fields of a user.
Sample code:
// Search for a friend by keyword
// Search criteria
V2TimFriendSearchParam searchParam = V2TimFriendSearchParam(
isSearchNickName: true, // Whether to search by nickname
isSearchRemark: true, // Whether to search by remarks
isSearchUserID: true, // Whether to search by user ID
keywordList: [], // Search keyword list. Up to five keywords are supported.
);
V2TimValueCallback<List<V2TimFriendInfoResult>> searchFriendsRes =
await TencentImSDKPlugin.v2TIMManager
.getFriendshipManager()
.searchFriends(searchParam: searchParam); // Search criteria
if (searchFriendsRes.code == 0) {
// Queried successfully
searchFriendsRes.data?.forEach((element) {
element.relation; // Friend type: `0` (Not a friend), `1` (The user is in your contacts.), `2` (You are in the user's contacts), `3` (Two-way friend)
element.resultCode; // Error code (query result)
element.resultInfo; // Description (query result)
// friendInfo: user profile of a friend. If you are not a friend, only the userID field has a value, and other fields are empty.
element.friendInfo
?.friendCustomInfo; // Custom friend field. You need to first configure a custom friend field in the console (**Feature Configuration** > **Custom Friend Field**) and then call this API to specify the field.
element.friendInfo?.friendGroups; // Lists to which a friend belongs
element.friendInfo?.friendRemark; // Friend remarks
element.friendInfo?.userID; // User ID
element.friendInfo?.userProfile
?.allowType; // Friend adding mode: `0` (Accept all friend requests), `1` (Reject all friend requests), `2` (Require approval for friend requests)
element.friendInfo?.userProfile?.birthday; // User's birthday
element.friendInfo?.userProfile?.customInfo; // User's custom status
element.friendInfo?.userProfile?.faceUrl; // User's profile photo URL
element.friendInfo?.userProfile?.gender; // User's gender: `1` (male), `2` (female)
element.friendInfo?.userProfile?.level; // User level
element.friendInfo?.userProfile?.nickName; // User nickname
element.friendInfo?.userProfile?.role; // User role
element.friendInfo?.userProfile?.selfSignature; // User signature
element.friendInfo?.userProfile?.userID; // User ID
});
}