215 lines
8.0 KiB
Dart
215 lines
8.0 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:circle_app/app/chat/TIMUIKitChat/tim_uikit_chat.dart';
|
|
import 'package:circle_app/app/minefragment/logic.dart';
|
|
import 'package:circle_app/components/my_app_bar.dart';
|
|
import 'package:circle_app/network/api.dart';
|
|
import 'package:circle_app/network/dio_manager.dart';
|
|
import 'package:circle_app/router/app_routers.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_chat_global_model.dart';
|
|
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
|
import 'package:tencent_cloud_chat_uikit/ui/controller/tim_uikit_chat_controller.dart';
|
|
|
|
import '../../util/eventBus.dart';
|
|
import 'logic.dart';
|
|
|
|
class ChatPage extends StatefulWidget {
|
|
|
|
ChatPage({Key? key})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<ChatPage> createState() => _ChatPageState();
|
|
}
|
|
|
|
class _ChatPageState extends State<ChatPage> {
|
|
// final logic = Get.find<ChatLogic>();
|
|
//
|
|
// final state = Get.find<ChatLogic>().state;
|
|
|
|
final TIMUIKitChatController _timuiKitChatController =
|
|
TIMUIKitChatController();
|
|
|
|
User? userInfoBean;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
initEventBus();
|
|
loadMyInfo();
|
|
}
|
|
|
|
|
|
initEventBus()async{
|
|
EventBusManager.on<SendCoustomMessage>().listen((event) async{
|
|
V2TimValueCallback<V2TimMessage>? sendMessageRes =
|
|
await _timuiKitChatController.sendMessage(
|
|
messageInfo: event.createCustomMessageRes?.data?.messageInfo);
|
|
if (sendMessageRes!.code == 0) {
|
|
// 发送成功
|
|
sendMessageRes.data?.customElem?.data; //自定义data
|
|
sendMessageRes.data?.customElem?.desc; //自定义desc
|
|
sendMessageRes.data?.customElem?.extension; //自定义extension
|
|
}
|
|
});
|
|
}
|
|
|
|
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(
|
|
backgroundColor:Colors.transparent,
|
|
showBottomContainer: false,
|
|
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) {
|
|
V2TimConversation con = Get.arguments;
|
|
return TIMChat(
|
|
conversation: Get.arguments,
|
|
customStickerPanel: renderCustomStickerPanel,
|
|
onTapAvatar :(String userId,TapDownDetails tapDownDetails)async{
|
|
var data = await Get.toNamed(AppRoutes.UserInfoActivity,arguments: userId.toString().split('_').last);
|
|
// setState(() {
|
|
//
|
|
// });
|
|
},
|
|
controller : _timuiKitChatController,
|
|
config: TIMUIKitChatConfig(
|
|
// 仅供演示,非全部配置项,实际使用中,可只传和默认项不同的参数,无需传入所有开关
|
|
isAllowClickAvatar: true,
|
|
isUseDefaultEmoji: true,
|
|
isAllowLongPressMessage: false,
|
|
isShowReadingStatus: true,
|
|
isShowGroupReadingStatus: true,
|
|
notificationTitle: "",
|
|
isUseMessageReaction: true,
|
|
|
|
notificationBody: (V2TimMessage message, String convID, ConvType convType) {
|
|
// V2TIM_ELEM_TYPE_NONE = 0, ///< 未知消息
|
|
// V2TIM_ELEM_TYPE_TEXT = 1, ///< 文本消息
|
|
// V2TIM_ELEM_TYPE_CUSTOM = 2, ///< 自定义消息
|
|
// V2TIM_ELEM_TYPE_IMAGE = 3, ///< 图片消息
|
|
// V2TIM_ELEM_TYPE_SOUND = 4, ///< 语音消息
|
|
// V2TIM_ELEM_TYPE_VIDEO = 5, ///< 视频消息
|
|
// V2TIM_ELEM_TYPE_FILE = 6, ///< 文件消息
|
|
// V2TIM_ELEM_TYPE_LOCATION = 7, ///< 地理位置消息
|
|
// V2TIM_ELEM_TYPE_FACE = 8, ///< 表情消息
|
|
// V2TIM_ELEM_TYPE_GROUP_TIPS = 9, ///< 群 Tips 消息
|
|
// V2TIM_ELEM_TYPE_MERGER = 10, ///< 合并消息
|
|
|
|
if (userInfoBean == null) {
|
|
loadMyInfo();
|
|
}
|
|
|
|
if (message.elemType ==1) {
|
|
return ((userInfoBean!.nickname! ?? '昵称待审核').isNotEmpty ? (userInfoBean!.nickname! ?? '昵称待审核') +':' : '') + message.textElem!.text! ?? '';
|
|
} else if (message.elemType == 3) {
|
|
return ((userInfoBean!.nickname! ?? '昵称待审核').isNotEmpty ? (userInfoBean!.nickname! ?? '昵称待审核') +':' : '') + '发了一张图片';
|
|
} else if (message.elemType == 4) {
|
|
return ((userInfoBean!.nickname! ?? '昵称待审核').isNotEmpty ? (userInfoBean!.nickname! ?? '昵称待审核') +':' : '') + '发了一条语音';
|
|
} else if (message.elemType == 5) {
|
|
return ((userInfoBean!.nickname! ?? '昵称待审核').isNotEmpty ? (userInfoBean!.nickname! ?? '昵称待审核') +':' : '') + '发了一条视频';
|
|
} else {
|
|
return ((userInfoBean!.nickname! ?? '昵称待审核').isNotEmpty ? (userInfoBean!.nickname! ?? '昵称待审核') +':' : '') + '发了一条消息';
|
|
}
|
|
|
|
},
|
|
groupReadReceiptPermissionList: [
|
|
GroupReceiptAllowType.work,
|
|
GroupReceiptAllowType.meeting,
|
|
GroupReceiptAllowType.public
|
|
],
|
|
),
|
|
customAppBar:MyAppBar(
|
|
centerTitle: con.showName! ?? '',
|
|
actionWdiget: GestureDetector(
|
|
onTap: () async{
|
|
var data = await Get.toNamed(AppRoutes.UserInfoActivity,arguments: con.userID.toString().split('_').last);
|
|
|
|
},
|
|
child: Text('TA的主页',style: TextStyle(color: const Color(0xFF00FFF4),fontSize:12.sp,fontWeight: FontWeight.w500),),
|
|
),
|
|
onPressed: () {},
|
|
),
|
|
|
|
userAvatarBuilder: (BuildContext context, V2TimMessage message) {
|
|
return avatarWidget((message.faceUrl?.isNotEmpty ?? false) ? message.faceUrl! : 'https://qiniuyun.leyuan666.com/quanzi/avatar/default.png');
|
|
},
|
|
|
|
);
|
|
}
|
|
|
|
avatarWidget(String url, {double width = 34}) {
|
|
print(url);
|
|
return GestureDetector(
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Image.asset(
|
|
getCircleImage('avatar_bg'),
|
|
width: width.sp,
|
|
),
|
|
url.contains("http") ? ClipOval(
|
|
child: CachedNetworkImage(
|
|
imageUrl:url,
|
|
width: (width - 2).sp,
|
|
height: (width - 2).sp,
|
|
fit: BoxFit.cover,
|
|
),
|
|
) : Text(url,style: TextStyle(color: Color(0xffF756FF),fontSize: 12.sp),)
|
|
],
|
|
));
|
|
}
|
|
|
|
void loadMyInfo() async {
|
|
var data = await DioManager.instance.get(url: Api.getUserMine);
|
|
if (data['code'] == 200) {
|
|
var bean = BaseResponse<MineResponseBean>.fromJson(
|
|
data, (data) => MineResponseBean.fromJson(data));
|
|
if (bean.isSuccess()) {
|
|
userInfoBean = bean.data.user!;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|