This commit is contained in:
2025-06-30 16:24:20 +08:00
commit 68de5eb048
454 changed files with 56921 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitAddFriendExample extends StatelessWidget {
const TIMUIKitAddFriendExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitAddFriend(onTapAlreadyFriendsItem: (String userID) {
});
}
}
+16
View File
@@ -0,0 +1,16 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitAddGroupExample extends StatelessWidget {
const TIMUIKitAddGroupExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitAddGroup(
onTapExistGroup: (groupID, conversation) {
},
);
}
}
+13
View File
@@ -0,0 +1,13 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitBlackListExample extends StatelessWidget {
const TIMUIKitBlackListExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const TIMUIKitBlackList();
}
}
+120
View File
@@ -0,0 +1,120 @@
// ignore_for_file: file_names
import 'package:example/TIMUIKitGroupProfileExample.dart';
import 'package:example/TIMUIKitProfileExample.dart';
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitChatExample extends StatelessWidget {
final V2TimConversation? selectedConversation;
const TIMUIKitChatExample({Key? key, this.selectedConversation})
: super(key: key);
Widget renderCustomStickerPanel({
sendTextMessage,
sendFaceMessage,
deleteText,
addCustomEmojiText,
addText,
List<CustomEmojiFaceData> defaultCustomEmojiStickerList = const [],
double? height,
double? width
}) {
final defaultEmojiList =
defaultCustomEmojiStickerList.map((customEmojiPackage) {
return CustomStickerPackage(
name: customEmojiPackage.name,
baseUrl: "assets/custom_face_resource/${customEmojiPackage.name}",
isEmoji: customEmojiPackage.isEmoji,
isDefaultEmoji: true,
stickerList: customEmojiPackage.list
.asMap()
.keys
.map((idx) =>
CustomSticker(index: idx, name: customEmojiPackage.list[idx]))
.toList(),
menuItem: CustomSticker(
index: 0,
name: customEmojiPackage.icon,
));
}).toList();
return StickerPanel(
sendTextMsg: sendTextMessage,
sendFaceMsg: (index, data) =>
sendFaceMessage(index + 1, (data.split("/")[3]).split("@")[0]),
deleteText: deleteText,
addText: addText,
addCustomEmojiText: addCustomEmojiText,
customStickerPackageList: [
...defaultEmojiList,
]);
}
@override
Widget build(BuildContext context) {
return TIMUIKitChat(
conversation: selectedConversation ??
V2TimConversation(
conversationID: "c2c_10040818",
userID: "10040818",
showName: "Test Chat",
type: 1),
customStickerPanel: renderCustomStickerPanel,
config: const TIMUIKitChatConfig(
// 仅供演示,非全部配置项,实际使用中,可只传和默认项不同的参数,无需传入所有开关
isAllowClickAvatar: true,
isAllowLongPressMessage: true,
isShowReadingStatus: true,
isShowGroupReadingStatus: true,
notificationTitle: "",
isUseMessageReaction: true,
groupReadReceiptPermissionList: [
GroupReceiptAllowType.work,
GroupReceiptAllowType.meeting,
GroupReceiptAllowType.public
],
),
appBarConfig: AppBar(
actions: [
IconButton(
padding: const EdgeInsets.only(left: 8, right: 16),
onPressed: () async {
final conversationType = selectedConversation?.type ?? 1;
if (conversationType == 1) {
final String? userID = selectedConversation?.userID;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text(userID ?? "User Profile")),
body: TIMUIKitProfileExample(userID: userID)),
));
} else {
final String? groupID = selectedConversation?.groupID;
if (groupID != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text(groupID)),
body: TIMUIKitGroupProfileExample(
groupID: groupID,
)),
));
}
}
},
icon: Image.asset(
'images/more.png',
package: 'tencent_cloud_chat_uikit',
height: 34,
width: 34,
))
],
),
);
}
}
+13
View File
@@ -0,0 +1,13 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitContactExample extends StatelessWidget {
const TIMUIKitContactExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const TIMUIKitContact();
}
}
@@ -0,0 +1,24 @@
// ignore_for_file: file_names, avoid_print
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/ui/views/TIMUIKitConversation/tim_uikit_conversation.dart';
import 'TIMUIKitChatExample.dart';
class TIMUIKitConversationExample extends StatelessWidget {
const TIMUIKitConversationExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitConversation(
onTapItem: (value) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TIMUIKitChatExample(
selectedConversation: value,
),
));
},
);
}
}
+13
View File
@@ -0,0 +1,13 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitGroupExample extends StatelessWidget {
const TIMUIKitGroupExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const TIMUIKitGroup();
}
}
@@ -0,0 +1,19 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitGroupProfileExample extends StatelessWidget {
final String? groupID;
const TIMUIKitGroupProfileExample({Key? key, this.groupID})
: super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitGroupProfile(
groupID: groupID ??
'@TGS#1X2AML5H6', // Please fill in here according to the actual cleaning
);
}
}
@@ -0,0 +1,13 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitNewContactExample extends StatelessWidget {
const TIMUIKitNewContactExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const TIMUIKitNewContact();
}
}
+16
View File
@@ -0,0 +1,16 @@
// ignore_for_file: file_names
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitProfileExample extends StatelessWidget {
final String? userID;
const TIMUIKitProfileExample({Key? key, this.userID}) : super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitProfile(
userID: userID ?? "10040818", // Please fill in here according to the actual cleaning
);
}
}
+18
View File
@@ -0,0 +1,18 @@
// ignore_for_file: avoid_print, file_names, deprecated_member_use
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
class TIMUIKitSearchExample extends StatelessWidget {
const TIMUIKitSearchExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TIMUIKitSearch(
onTapConversation: (conv, message) {
},
onEnterConversation: (V2TimConversation conversation, String keyword) {},
);
}
}
+210
View File
@@ -0,0 +1,210 @@
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/enum/V2TimSDKListener.dart';
import 'package:tencent_cloud_chat_sdk/enum/log_level_enum.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_callback.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_user_full_info.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
import 'TIMUIKitAddFriendExample.dart';
import 'TIMUIKitAddGroupExample.dart';
import 'TIMUIKitBlackListExample.dart';
import 'TIMUIKitChatExample.dart';
import 'TIMUIKitContactExample.dart';
import 'TIMUIKitConversationExample.dart';
import 'TIMUIKitGroupExample.dart';
import 'TIMUIKitGroupProfileExample.dart';
import 'TIMUIKitNewContactExample.dart';
import 'TIMUIKitProfileExample.dart';
import 'TIMUIKitSearchExample.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tencent IM UIKit',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Tencent Cloud Chat UIKit'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
initTIMUIKIT();
}
CoreServicesImpl timCoreInstance = TIMUIKitCore.getInstance();
int getSDKAPPID() {
return const int.fromEnvironment('SDK_APPID', defaultValue: 0);
}
String getUserID() {
return const String.fromEnvironment('LOGINUSERID', defaultValue: "10045363");
}
String getSecret() {
return const String.fromEnvironment('SECRET', defaultValue: "");
}
String getUsersig() {
return const String.fromEnvironment('USERSIG', defaultValue: "");
}
initTIMUIKIT() async {
int sdkappid = getSDKAPPID();
String userid = getUserID();
String secret = getSecret();
String usersig = getUsersig();
if (sdkappid == 0 || userid == '' || secret == '' || usersig == '') {
print("The running parameters are abnormal, please check");
return;
}
await timCoreInstance.init(
sdkAppID: sdkappid,
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG,
listener: V2TimSDKListener(
onConnectFailed: (code, error) {},
onConnectSuccess: () {},
onConnecting: () {},
onKickedOffline: () {},
onSelfInfoUpdated: (V2TimUserFullInfo info) {},
onUserSigExpired: () {},
),
);
V2TimCallback res =
await timCoreInstance.login(userID: userid, userSig: usersig);
print(
"Log in to Tencent Cloud Instant Messaging IM Return:${res.toJson()}");
}
getAPIWidget(String apiName) {
switch (apiName) {
case 'TIMUIKitConversation':
return const TIMUIKitConversationExample();
case 'TIMUIKitChat':
return const TIMUIKitChatExample();
case 'TIMUIKitProfile':
return const TIMUIKitProfileExample();
case 'TIMUIKitAddFriend':
return const TIMUIKitAddFriendExample();
case 'TIMUIKitAddGroup':
return const TIMUIKitAddGroupExample();
case 'TIMUIKitBlackList':
return const TIMUIKitBlackListExample();
case 'TIMUIKitContact':
return const TIMUIKitContactExample();
case 'TIMUIKitGroup':
return const TIMUIKitGroupExample();
case 'TIMUIKitGroupProfile':
return const TIMUIKitGroupProfileExample();
case 'TIMUIKitNewContact':
return const TIMUIKitNewContactExample();
case 'TIMUIKitSearch':
return const TIMUIKitSearchExample();
}
}
openExamplePage(String apiName) {
if (apiConfig.contains(apiName)) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
title: Text(apiName),
),
body: getAPIWidget(apiName),
),
),
);
} else {
print("no such ket");
}
}
List<String> apiConfig = [
"TIMUIKitConversation",
"TIMUIKitChat",
"TIMUIKitProfile",
"TIMUIKitAddFriend",
"TIMUIKitAddGroup",
"TIMUIKitBlackList",
"TIMUIKitContact",
"TIMUIKitGroup",
"TIMUIKitGroupProfile",
"TIMUIKitNewContact",
"TIMUIKitSearch"
];
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
children: apiConfig
.map(
(e) => Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
openExamplePage(e);
},
child: Text(e),
),
)
],
),
)
.toList(),
),
),
),
);
}
}