UI Kit quickstart
Instant messaging connects people wherever they are and allows them to communicate with others in real time. Agora offers an open-source Chat UI Kit project on GitHub. With built-in user interfaces for key Chat features, the Agora Chat UI Kit enables you to quickly embed real-time messaging into your app without requiring extra effort on the UI.
For the latest Agora Chat UIKit documentation, refer to the UIKit 2.x Documentation GitHub repository.
Legacy UIkit 1.x documentation
This page shows sample code to add peer-to-peer messaging into your app by using the Agora Chat UI Kit.
Understand the tech
The following figure shows the workflow of how clients send and receive peer-to-peer messages:
Chat UI kit workflow
- Clients retrieve a token from your app server.
- Client A and Client B log in to Agora Chat.
- Client A sends a message to Client B. The message is sent to the Agora Chat server, and the server delivers the message to Client B. When Client B receives the message, the SDK triggers an event. Client B listens for the event and gets the message.
Prerequisites
-
Flutter 2.10 or higher.
-
Dart 2.16 or higher.
-
If your target platform is iOS:
- macOS
- Xcode 12.4 or higher with Xcode Command Line Tools
- CocoaPods
- An iOS emulator or a physical iOS device running iOS 10.0 or higher
-
If your target platform is Android:
- macOS or Windows
- Android Studio 4.0 or higher with JDK 1.8 or higher
- An Android emulator or a physical Android device running Android SDK API 21 or higher
Project setup
Follow these steps to create the environment necessary to integrate Chat UI Kit into your app:
-
Create a new Flutter project for iOS and Android
-
In the terminal, run the following command:
-
Integrate the UI Kit using pub.dev (Recommended)
Execute the following commands in the
uikit_demo
directory:
-
-
Add permissions for network and device access
-
For Android, in
/app/Manifests/AndroidManifest.xml
, add the following permissions after</application>
: -
For iOS, open info in the project navigation panel, and add the following properties to the Property List:
Key Type Value Privacy - Microphone Usage Description
String For microphone access Privacy - Camera Usage Description
String For camera access Privacy - Photo Library Usage Description
String For photo library access
-
-
Prevent code obfuscation
In the
example/android/app/proguard-rules.pro
file, add the following lines:
This section shows how to use the Chat UI Kit to implement peer-to-peer messaging in your app.
The agora_chat_uikit
library provides the logic and UI to implement the following Chat functions:
- Send, receive, and display messages
- Shows the unread message count, and clear messages. Text, image, emoji, file, and audio messages are supported
- Delete conversations and messages
- Customize the UI
Chat UI Kit widgets
Widget | Function | Description |
ChatUIKit | The root of all widgets in Chat UI Kit. | ChatConversationsView |
Conversation list | Presents the conversation information, including the user's avatar, nickname, content of the last message, unread message count, and the time when the last message was sent or received. |
Delete conversation | Deletes the conversation from the conversation list. | |
ChatMessagesView |
Message sender | Sends text, emoji, image, file, and voice messages. |
Delete messages | Deletes messages. | |
Recall message | Recalls message that were sent within 120 seconds. | |
Read mark | You receive a read receipt after retrieving your message. | |
Message sent state | Display the status after the message is sent. | |
Display message | Displays one-to-one messages and group messages, including the user's avatar, nickname, the message content, sending or reception time, sending status, and read status. Text, image, emoji, file, voice, and video messages can be displayed. |
Use the following UI Kit widgets to implement Chat functionality with the associated UI in your projects.
ChatUIKit
Place a ChatUIKit
widget at the top of your widget tree to help refresh the ChatConversationsView
when returning from ChatMessagesView
.
The ChatUIKit
widget also enables you to customize the theme settings.
Property | Description |
---|---|
theme | Chat UI Kit theme for setting component styles. If this property is not set, the default style is used. |
ChatMessagesView
You use ChatMessagesView
to manage text, images, emojis, files, and voice messages:
- Send and receive messages
- Delete messages
- Recall messages
Property | Description |
---|---|
conversation | The ChatConversation to which the messages belong. |
inputBarTextEditingController | Text input widget text editing controller. |
background | The background widget. |
inputBar | Text input component. If you don't pass in this property, ChatInputBar is used by default. |
onTap | Message bubble click callback. |
onBubbleLongPress | Callback for holding a message bubble. |
onBubbleDoubleTap | Callback for double-clicking a message bubble. |
avatarBuilder | Avatar component builder. |
nicknameBuilder | Nickname component builder. |
itemBuilder | Message bubble. If you don't set this property, the default bubble is used. |
moreItems | Action items displayed after a message bubble is held down. If you return null in onBubbleLongPress , moreItems is used. This property involves three default actions: copy, delete, and recall. |
messageListViewController | Message list controller. You are advised to use the default value. For details, see ChatMessageListController . |
willSendMessage | Text message pre-sending callback. This callback needs to return a ChatMessage object. |
onError | Error callback, such as no permissions. |
enableScrollBar | Whether to enable the scroll bar. The scroll bar is enabled by default. |
needDismissInputWidget | Callback for dismissing the input widget. If you use a custom input widget, dismiss the input widget when you receive this callback, for example, by calling FocusNode.unfocus . See ChatInputBar . |
inputBarMoreActionsOnTap | The callback for clicking the plus symbol next to the input box. You need to return the ChatBottomSheetItems list. |
ChatConversationsView
The 'ChatConversationsView' allows you to quickly display and manage the current conversations.
Property | Description |
---|---|
controller | The ChatConversationsView controller. |
itemBuilder | Conversation list item builder. Return a widget if you need to customize it. |
avatarBuilder | Avatar builder. If this property is not implemented or you return null , the default avatar is used. |
nicknameBuilder | Nickname builder. If you don't set this property or return null , the conversation ID is displayed. |
onItemTap | The callback of the click event of the conversation list item. |
backgroundWidgetWhenListEmpty | Background widget when the list is empty. |
enablePullReload | Whether to enable drop-down refresh. |
Local integration
The recommended integration method for the Chat UI Kit is using pub.dev. You can also download the project manually for integration. To do this, open the uikit_demo
project in your IDE and take the following steps:
-
Clone the Chat UIKit for Flutter repository.
-
Add the UI Kit dependency:
-
Replace the code in
lib/main.dart
with the following: -
To create a
MessagesPage
refer to the following code:
Test your app
To test the UI Kit Chat features example:
-
In
example/lib/main.dart
, set theappKey
,userId
, andagoraToken
to valid values. -
Click Sign In. You see a log message confirming sign-in success.
-
Run the app on another device or simulator. Ensure that the
userId
values are unique. -
On the first device or simulator, enter the user id you just created and click Start Chat. You can now start chatting between the two clients.
Reference
Refer to the fully featured AgoraChat-UIKit-flutter demo app as an implementation reference. To customize the UI Kit, refer to the following information.
Customize colors
You can set the color when adding ChatUIKit
.
Add an avatar
Add a nickname
Add the bubble click event
Customize the message item widget
Customize the input widget
Delete all Messages in the current conversation
Customize actions displayed upon a click of the plus symbol in the page