TIMUIKitCore
provides two static methods: getInstance
and getSDKInstance
.
getInstance
: returns a CoreServicesImpl
instance.getSDKInstance
: returns an SDK instance.CoreServicesImpl
is the TIMUIKit core class, which provides methods for initialization, login, logout, and getting user information.
import 'package:tim_ui_kit/tim_ui_kit.dart';
final CoreServicesImpl _coreInstance = TIMUIKitCore.getInstance();
final V2TIMManager _sdkInstance = TIMUIKitCore.getSDKInstance();
/// init
_coreInstance.init(
sdkAppID: 0, // SDKAppID obtained from the console
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG,
listener: V2TimSDKListener());
/// unInit
_coreInstance.unInit();
/// login
_coreInstance.login(
userID: 0, // User ID
userSig: "" // See the official documentation for userSig
)
/// logout
_coreInstance.logout();
/// getUsersInfo
_coreInstance.getUsersInfo(userIDList: ["123", "456"]);
/// setOfflinePushConfig
_coreInstance.setOfflinePushConfig(
businessID: businessID, // IM console certificate ID, which does not need to be entered for TPNS integration
token: token, // Token obtained when you register your application with the vendor platform or TPNS
isTPNSToken: false // Whether to integrate TPNS, or whether the token is obtained from TPNS
)
/// setSelfInfo
_coreInstance.setSelfInfo(userFullInfo: userFullInfo) // Set user information
/// setTheme
_coreInstance.setTheme(TUITheme theme: theme) // Set the theme color
/*
TUITheme(
// Primary color of the application
final Color? primaryColor;
// Secondary color of the application
final Color? secondaryColor;
// Tip (information) color, for secondary actions or tips
final Color? infoColor;
// Light background color, which is lighter than the primary background color and is used to fill gaps or shadows
final Color? weakBackgroundColor;
// Light dividing line color, for dividing lines or borders
final Color? weakDividerColor;
// Light font color
final Color? weakTextColor;
// Dark font color
final Color? darkTextColor;
// Light primary color, for app bars or panels
final Color? lightPrimaryColor;
// Font color
final Color? textColor;
// Caution color, for high-risk operations
final Color? cautionColor;
// Group owner color
final Color? ownerColor;
// Group admin color
final Color? adminColor;)
*/
CoreServicesImpl
instance.V2TIMManager
SDK instance. For the usage details, see Flutter IM SDK documentation.TIMUIKitConversation
is a conversation component for getting user conversation lists. It provides a set of UIs by default and allows users to customize the number of items. It also provides the corresponding TIMUIKitConversationController
.
import 'package:tim_ui_kit/tim_ui_kit.dart';
final TIMUIKitConversationController _controller =
TIMUIKitConversationController();
void _handleOnConvItemTaped(V2TimConversation? selectedConv) {
/// Processing logic, from which you can redirect to the chat UI
}
List<ConversationItemSlidablePanel> _itemSlidableBuilder(
V2TimConversation conversationItem) {
return [
ConversationItemSlidablePanel(
onPressed: (context) {
_clearHistory(conversationItem);
},
backgroundColor: hexToColor("006EFF"),
foregroundColor: Colors.white,
label: 'Clear chat',
autoClose: true,
),
ConversationItemSlidablePanel(
onPressed: (context) {
_pinConversation(conversationItem);
},
backgroundColor: hexToColor("FF9C19"),
foregroundColor: Colors.white,
label: conversationItem.isPinned! ? 'Unpin from top' : 'Pin to top',
)
];
}
TIMUIKitConversation(
onTapItem: _handleOnConvItemTaped, /// Conversation item tapping callback, which can be used to redirect to the chat UI
itemSlidableBuilder: _itemSlidableBuilder, /// Action of sliding a conversation item to the left. You can customize the action, for example, configure the action to pin a conversation to the top.
controller: _controller, /// Conversation component controller. You can use it to get conversation data, configure conversation data, pin a conversation to the top, and so on.
itembuilder: (conversationItem) {} /// UI for customizing conversation items. It can be used with `TIMUIKitConversationController` to implement business logic.
conversationCollector: (conversation) {} /// Conversation collector. You can configure whether to display conversations.
)
count
specifies the number of conversations loaded each time.count
specifies the number of conversations reloaded each time.TIMUIKitChat
is a chat component that provides the capability to display message lists and send messages, and supports the customization of display of various custom message types. It can also be used with TIMUIKitChatController to implement the local storage and pre-rendering of messages.
Currently, TIMUIKitChat
can be used to parse the following types of message:
import 'package:tim_ui_kit/tim_ui_kit.dart';
TIMUIKitChat(
conversationID: "", /// Conversation ID
conversationType: 0, /// Conversation type
conversationShowName: "", /// Conversation display name
appBarActions: [], /// App bar action. You can use it to redirect to the group profile page or user profile page.
onTapAvatar: _onTapAvatar, /// Profile photo tapping callback. You can use it to redirect to the user profile page.
showNickName: false, /// Whether to display the nickname
messageItemBuilder: (message) {
/// Custom message constructor. If `null` is returned, the default constructor is used.
},
exteraTipsActionItemBuilder: (message) {
/// Message tap-and-hold tip customization. Configure it according to your business requirements.
}
)
TIMUIKitProfile
is used to display user profiles. It also allows you to customize and add actions.
TIMUIKitProfile(
userID: "",
controller: TIMUIKitProfileController(), // Profile Controller
operationListBuilder: (context, userInfo, conversation) {
/// Custom action, such as setting the Mute Notifications option and pinning a message to the top. If no value is passed in, the default action is used by default.
},
bottomOperationBuilder: (context, friendInfo, conversation) {
/// Bottom action, such as deleting a friend
},
handleProfileDetailCardTap: (BuildContext context, V2TimUserFullInfo? userFullInfo) {
/// User profile tile tapping callback
},
canJumpToPersonalProfile: false, // Whether to redirect to the user profile page
)
isPined
indicates whether to pin the conversation to the top. convID
indicates the ID of the conversation to be pinned to the top.shouldAdd
indicates whether to add the user to the blocklist. userID
indicates the ID of the user to be added to the blocklist.0
means to accept all friend requests. 1
means requiring approval for friend requests. 2
means to reject all friend requests.userID
indicates the ID of the user whose remarks are to be updated. remark
indicates the remarks.userID
indicates the ID of the friend to be added.TIMUIKitGroupProfile
is the group management UI. It also allows you to customize and add actions.
TIMUIKitGroupProfile(
groupID: "", // Group ID. Required
operationListBuilder:(){}, // Action custom constructor
bottomOperationListBuilder: () {}, // Bottom action custom constructor
)
operationListBuilder
and bottomOperationListBuilder
enable you to configure operation items. They can be used together with components as needed.
TIMUIKitBlackList
is the blocklist component.
TIMUIKitBlackList(
onTapItem: (_) {}, /// Item tapping callback
emptyBuilder: () {} /// Displayed when the list is empty
itemBuilder: () {} /// Custom item
)
TIMUIKitGroup
is the group list component.
TIMUIKitGroup(
onTapItem: (_) {}, /// Item tapping callback
emptyBuilder: () {} /// Displayed when the list is empty
itemBuilder: () {} /// Custom item
)
TIMUIKitContact
is the contacts component. It provides the list of contacts.
import 'package:tim_ui_kit/tim_ui_kit.dart';
TIMUIKitContact(
topList: [
TopListItem(name: "New contact", id: "newContact"),
TopListItem(name: "My groups", id: "groupList"),
TopListItem(name: "Blocklist", id: "blackList")
], /// Top action list
topListItemBuilder: _topListBuilder, /// Top action list constructor
onTapItem: (item) { }, /// Contact tapping
emptyBuilder: (context) => const Center(
child: Text("No contact"),
), /// Displayed when the contact list is empty
);
TIMUIKitNewContact
is the new contacts UI.
TIMUIKitNewContact(
onAccept: (applicationInfo) {
/// Friend request acceptance callback
},
onRefuse: (applicationInfo) {
/// Friend request rejection callback
},
emptyBuilder: () {
/// Callback when no friend request is received
},
itemBuilder: () {
/// Custom friend request item constructor
}
)
Was this page helpful?