3. In the Chat console, select your application and click Auxiliary Tools > UserSig Generation & Verification on the left sidebar. Create two UserID values and their UserSig values, and copy the UserID, Key, and UserSig so they can be used to log in later.
Note:
This account is for development and testing only. Before the application is launched, the correct UserSig distribution method is to use the server to generate UserSig and provide an application-oriented API. When UserSig is needed, your application can send a request to the business server for a dynamic UserSig. For more information, see Generating UserSig.
Selecting a Suitable Scheme to Integrate the SDK for Flutter
The Chat sample app is a complete chat application built with UIKit. If you need to implement chat scenarios, you can use the sample app for secondary development. Try it out here.
The Chat UI component library UIKit provides common UI components, such as conversation list, chat UI, and contacts. You can use the component library to quickly build a custom Chat application as needed. This scheme is recommended.
Open lib/config.dart, and specify the sdkappid, userid, and usersig obtained and generated in the previous step.
3. Run the app.
flutter run
Sample app code structure
Folder
Features
lib
Program core directory
lib/desktop
Desktop adaptation related code
lib/setting
The related code for Profile and Settings pages
The lib directory's lib/main.dart file is the core file of this sample app program. As you can see, there are several lines of key code. The List<Widget> pages component list is passed into bottomNavigation for page switching.
Although the new version of UIKit has many components, these components are built-in support for routing and navigation. That is, to minimize the use, only manually use the TencentCloudChatConversation conversation list component and TencentCloudChatContact contacts component, you can use all associated UIKit components, including the Message, Contact, and Group Profile components, etc. These components can be navigated to through the components you manually import.
If you have more advanced customization requirements for using the UIKit, you can refer to the quick start document of UIKit.
Scheme 2. Using UIKit Component Library to Quickly Integrate Chat Capabilities
Our new Flutter Chat UIKit V2 provides developers with a comprehensive set of tools to easily create feature-rich chat applications.
It is built with a modular approach, allowing you to pick and choose the components you need while keeping your application lightweight and efficient.
This section provides a brief overview of how to integrate and use the UIKit. For a more comprehensive guide, please refer to the Quick Start documentation provided Integrating Basic Features - Flutter.
Compatibility
Our UIKit supports both mobile, tablet and desktop UI styles, and is compatible with Android, iOS, macOS, Windows, and Web (will be supported in future versions).
It comes with built-in support for English, Simplified Chinese, Traditional Chinese, Japanese, Korean, and Arabic languages (with support for Arabic RTL interface), and light and dark appearance styles.
Requirements
Flutter version: 3.16 or above
Dart version: 3.0 or above
Getting Started
To start using our UIKit, first import the base package, tencent_cloud_chat.
Next, import the required UI component packages that suit your needs from the following list:
sdkAppID: 0, // Replace 0 with the SDKAppID of your Chat application when integrating
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG, // Log
listener: V2TimSDKListener(),
);
In this step, you can mount some listeners to the Chat SDK, mainly including those for network status and user information changes. For more information, see here.
V2TimCallback res = await TencentImSDKPlugin.v2TIMManager.login (
userID: userID,
userSig: userSig,
);
Note:
The test account is for development and testing only. Before the application is launched, the correct method for generating a UserSig is to integrate the UserSig calculation code into your server and provide an application-oriented API. When UserSig is needed, your application can send a request to the business server for a dynamic UserSig. For more information, see Generating UserSig.
1. Call createTextMessage(String) to create a text message.
2. Get the message ID from the returned value.
3. Call sendMessage() and pass in the id, while receiver can be the ID of the other test account created earlier, groupID is not required for sending a one-to-one message.
String id = createMessage.data!.id!; // The message creation ID
V2TimValueCallback<V2TimMessage> res = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.sendMessage(
id: id, // Pass in the message creation ID to
receiver: "The userID of the destination user",
groupID: "The groupID of the destination group",
);
Note:
If sending fails, it may be that your `sdkAppID` doesn't support sending messages to strangers. In this case, you can disable the relationship check feature in the console.
Log in with the second test account to load the conversation list.
The conversation list can be obtained in two ways:
1. Listen for the persistent connection callback to update the conversation list in real time.
2. Call an API to get the conversation list at certain time points.
Common use cases include:
Getting the conversation list when the application starts and listening for the persistent connection callback to update the conversation list in real time.
Requesting the conversation list at certain time points
To get the conversation list, you need to maintain nextSeq and record its current position.
Additional configurations are required for the macOS platform. Follow the steps below to configure the macOS platform:
1. Open the macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements files in your project.
2. Add the following lines to each file:
<key>com.apple.security.network.client</key>
<true/>
These lines grant your app the necessary permissions to access the network as a client.
This configuration is essential for ensuring proper communication between your app and the backend services on the macOS platform.
FAQs
What should I do if Pods dependency installation fails in iOS devices?
Solution 1: If an error occurs after the configuration, click Product > Clean Build Folder, clear the product, and run pod install or flutter run again.
Solution 2: Manually delete the ios/Pods folder and the ios/Podfile.lock file and run the following command to reinstall the dependencies
cd ios
sudo gem install ffi
pod install --repo-update
Flutter environment
If you want to check the Flutter environment, run Flutter doctor to detect whether the Flutter environment is ready.
What should I do if an error occurs when I run the Demo on a Windows platform?
Nuget.exe not found, trying to download or use cached version.
This error message indicates that nuget.exe was not found on your system, so the program is attempting to download or use a cached one. Nuget.exe is a command-line utility for the NuGet Package Manager and is used to manage dependencies in .NET projects.
To fix this issue, you can manually download and install nuget.exe by following these steps: