基础页面
This commit is contained in:
82
lib/views/conversation/index_page.dart
Normal file
82
lib/views/conversation/index_page.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:chat/controllers/group_controller.dart';
|
||||
import 'package:chat/controllers/private_controller.dart';
|
||||
import 'package:chat/routes/conversation_routes.dart';
|
||||
import 'package:chat/services/tim/conversation_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tencent_im_sdk_plugin/enum/conversation_type.dart';
|
||||
import 'package:tencent_im_sdk_plugin/models/v2_tim_conversation.dart';
|
||||
|
||||
class ConversationPage extends StatefulWidget {
|
||||
const ConversationPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ConversationPageState createState() => _ConversationPageState();
|
||||
}
|
||||
|
||||
class _ConversationPageState extends State<ConversationPage> {
|
||||
late final V2TimConversation conversation;
|
||||
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
final GlobalKey<dynamic> inputextField = GlobalKey();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
conversation = Get.arguments['conversation'];
|
||||
|
||||
/// 标记会话内消息已读
|
||||
TimConversationService.to.markAsRead(conversation);
|
||||
if (conversation.type == ConversationType.V2TIM_GROUP) {
|
||||
GroupController.to.setCurrentGroup(conversation.groupID!);
|
||||
} else {
|
||||
PrivateController.to.setCurrentFriend(conversation.userID!);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
inputextField.currentState.hideAllPanel();
|
||||
},
|
||||
child: Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
title: conversation.type == ConversationType.V2TIM_GROUP
|
||||
? GetX<GroupController>(
|
||||
builder: (_) {
|
||||
return Text(
|
||||
_.currentGroup.value.conversation?.showName ?? '',
|
||||
);
|
||||
},
|
||||
)
|
||||
: GetX<PrivateController>(
|
||||
builder: (_) {
|
||||
return Text(
|
||||
_.currentFriend.value.conversation?.showName ?? '',
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
_topRightAction(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _topRightAction() {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
onPressed: () {
|
||||
conversation.type == ConversationType.V2TIM_GROUP
|
||||
? Get.toNamed(
|
||||
ConversationRoutes.infoGroup,
|
||||
)
|
||||
: Get.toNamed(
|
||||
ConversationRoutes.infoPrivate,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
235
lib/views/conversation/info/group_page.dart
Normal file
235
lib/views/conversation/info/group_page.dart
Normal file
@@ -0,0 +1,235 @@
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/controllers/group_controller.dart';
|
||||
import 'package:chat/routes/contact_routes.dart';
|
||||
import 'package:chat/services/tim/conversation_service.dart';
|
||||
import 'package:chat/services/tim/group_service.dart';
|
||||
import 'package:chat/views/conversation/info/widgets/group_member_preview.dart';
|
||||
import 'package:chat/views/home/widgets/action_button.dart';
|
||||
import 'package:chat/views/home/widgets/action_item.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ConversationInfoGroupPage extends StatelessWidget {
|
||||
const ConversationInfoGroupPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
GroupController.to.fetchGroupMemberList();
|
||||
|
||||
return GetX<GroupController>(builder: (_) {
|
||||
var currentGroup = _.currentGroup.value;
|
||||
var group = _.currentGroup.value.group;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('聊天信息(${group?.memberCount})'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
const GroupMemberPreview(),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
color: AppColors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
ActionItem(
|
||||
'群聊名称',
|
||||
extend: group?.groupName,
|
||||
onTap: () {
|
||||
if (currentGroup.isAdmin || currentGroup.isOwner) {
|
||||
// Get.toNamed(
|
||||
// ImRoutes.groupName,
|
||||
// );
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(height: 0, indent: 16),
|
||||
ActionItem(
|
||||
'群二维码',
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupQrCode,
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 0, indent: 16),
|
||||
ActionItem(
|
||||
'群公告',
|
||||
bottom: group?.notification,
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupNotification,
|
||||
);
|
||||
},
|
||||
),
|
||||
Visibility(
|
||||
visible: currentGroup.isAdmin || currentGroup.isOwner,
|
||||
child: const Divider(
|
||||
height: 0,
|
||||
indent: 16,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: currentGroup.isAdmin || currentGroup.isOwner,
|
||||
child: ActionItem(
|
||||
'群管理',
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupManage,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: currentGroup.isAdmin || currentGroup.isOwner,
|
||||
child: const Divider(
|
||||
height: 0,
|
||||
indent: 16,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: currentGroup.isAdmin || currentGroup.isOwner,
|
||||
child: ActionItem(
|
||||
'加群申请',
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupApprove,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
color: AppColors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
ActionItem(
|
||||
'查找聊天记录',
|
||||
onTap: () {
|
||||
// Get.toNamed(
|
||||
// ImRoutes.conversationSearch,
|
||||
// );
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
color: AppColors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
ActionItem(
|
||||
'消息免打扰',
|
||||
rightWidget: SizedBox(
|
||||
height: 24,
|
||||
child: Switch(
|
||||
value:
|
||||
_.currentGroup.value.conversation!.recvOpt == 1,
|
||||
onChanged: (e) async {
|
||||
_.toggleReceiveOpt();
|
||||
},
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 0,
|
||||
indent: 16,
|
||||
),
|
||||
ActionItem(
|
||||
'置顶聊天',
|
||||
rightWidget: SizedBox(
|
||||
height: 24,
|
||||
child: Switch(
|
||||
value: _.currentGroup.value.conversation!.isPinned!,
|
||||
onChanged: (e) async {
|
||||
_.togglePinned();
|
||||
},
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
color: AppColors.white,
|
||||
child: Column(
|
||||
children: [
|
||||
ActionItem(
|
||||
'我在群里的昵称',
|
||||
extend: _.currentGroup.value.selfInfo?.nameCard ?? '',
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupNickname,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Column(
|
||||
children: [
|
||||
ActionButton(
|
||||
'清空聊天记录',
|
||||
onTap: () async {
|
||||
OkCancelResult result = await showOkCancelAlertDialog(
|
||||
style: AdaptiveStyle.iOS,
|
||||
context: Get.context!,
|
||||
title: '系统提示',
|
||||
message: '将删除该聊天记录,是否继续?',
|
||||
okLabel: '确定',
|
||||
cancelLabel: '取消',
|
||||
defaultType: OkCancelAlertDefaultType.ok,
|
||||
);
|
||||
|
||||
if (result == OkCancelResult.ok) {
|
||||
TimConversationService.to.clearHistoryMessage(
|
||||
_.currentGroup.value.conversation!,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (!currentGroup.isOwner) const Divider(height: 0),
|
||||
ActionButton(
|
||||
'删除并退出',
|
||||
onTap: () async {
|
||||
OkCancelResult result = await showOkCancelAlertDialog(
|
||||
style: AdaptiveStyle.iOS,
|
||||
context: Get.context!,
|
||||
title: '系统提示',
|
||||
message: '将删除并退出该群组,是否继续?',
|
||||
okLabel: '确定',
|
||||
cancelLabel: '取消',
|
||||
defaultType: OkCancelAlertDefaultType.ok,
|
||||
);
|
||||
|
||||
if (result == OkCancelResult.ok) {
|
||||
TimGroupService.to.quit(
|
||||
group!,
|
||||
);
|
||||
Navigator.popUntil(context, (route) => route.isFirst);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
157
lib/views/conversation/info/private_page.dart
Normal file
157
lib/views/conversation/info/private_page.dart
Normal file
@@ -0,0 +1,157 @@
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/controllers/private_controller.dart';
|
||||
import 'package:chat/routes/contact_routes.dart';
|
||||
import 'package:chat/services/tim/conversation_service.dart';
|
||||
import 'package:chat/views/home/widgets/action_item.dart';
|
||||
import 'package:chat/widgets/custom_avatar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ConversationInfoPrivatePage extends StatelessWidget {
|
||||
const ConversationInfoPrivatePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetX<PrivateController>(builder: (_) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('聊天信息'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(color: AppColors.white),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.friendProfile,
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
CustomAvatar(
|
||||
_.currentFriend.value.userProfile?.faceUrl,
|
||||
size: 54,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_.currentFriend.value.conversation!.showName!,
|
||||
style: const TextStyle(
|
||||
color: AppColors.unactive,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupCreate,
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 54,
|
||||
height: 54,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.unactive.withOpacity(0.1),
|
||||
border: Border.all(
|
||||
color: AppColors.unactive.withOpacity(0.3),
|
||||
width: 0.4,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 0),
|
||||
const SizedBox(height: 8),
|
||||
const Divider(height: 0),
|
||||
ActionItem(
|
||||
'查找聊天记录',
|
||||
onTap: () {
|
||||
// Get.toNamed(
|
||||
// ImRoutes.conversationSearch,
|
||||
// );
|
||||
},
|
||||
),
|
||||
const Divider(height: 0),
|
||||
const SizedBox(height: 8),
|
||||
const Divider(height: 0),
|
||||
ActionItem(
|
||||
'消息免打扰',
|
||||
rightWidget: SizedBox(
|
||||
height: 24,
|
||||
child: Switch(
|
||||
value: _.currentFriend.value.conversation!.recvOpt == 1,
|
||||
onChanged: (e) async {
|
||||
_.changeReceiveOpt();
|
||||
},
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 0,
|
||||
indent: 16,
|
||||
),
|
||||
ActionItem(
|
||||
'置顶聊天',
|
||||
rightWidget: SizedBox(
|
||||
height: 24,
|
||||
child: Switch(
|
||||
value: _.currentFriend.value.conversation!.isPinned!,
|
||||
onChanged: (e) async {
|
||||
_.togglePinned();
|
||||
},
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 0),
|
||||
const SizedBox(height: 8),
|
||||
const Divider(height: 0),
|
||||
ActionItem(
|
||||
'清空聊天记录',
|
||||
onTap: () async {
|
||||
OkCancelResult result = await showOkCancelAlertDialog(
|
||||
style: AdaptiveStyle.iOS,
|
||||
context: Get.context!,
|
||||
title: '系统提示',
|
||||
message: '将删除该聊天记录,是否继续?',
|
||||
okLabel: '确定',
|
||||
cancelLabel: '取消',
|
||||
defaultType: OkCancelAlertDefaultType.ok,
|
||||
);
|
||||
|
||||
if (result == OkCancelResult.ok) {
|
||||
TimConversationService.to.clearHistoryMessage(
|
||||
_.currentFriend.value.conversation!,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(height: 0),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
209
lib/views/conversation/info/widgets/group_member_preview.dart
Normal file
209
lib/views/conversation/info/widgets/group_member_preview.dart
Normal file
@@ -0,0 +1,209 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:chat/controllers/group_controller.dart';
|
||||
import 'package:chat/controllers/private_controller.dart';
|
||||
import 'package:chat/routes/contact_routes.dart';
|
||||
import 'package:chat/widgets/custom_avatar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tencent_im_sdk_plugin/enum/group_member_role.dart';
|
||||
import 'package:tencent_im_sdk_plugin/models/v2_tim_group_member_full_info.dart';
|
||||
|
||||
class GroupMemberPreview extends StatelessWidget {
|
||||
const GroupMemberPreview({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetX<GroupController>(builder: (_) {
|
||||
List<Widget> items = List<Widget>.empty(growable: true);
|
||||
|
||||
if (_.currentGroup.value.memberList != null) {
|
||||
var members = _.currentGroup.value.memberList!;
|
||||
|
||||
if (members.length > 13) {
|
||||
members = members.sublist(0, 13);
|
||||
}
|
||||
|
||||
for (var item in members) {
|
||||
items.add(_memberItem(item!));
|
||||
}
|
||||
}
|
||||
|
||||
/// 因为 Public 类型的群,不支持邀请功能,用户只能主动申请加群
|
||||
items.add(
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
OkCancelResult result = await showOkCancelAlertDialog(
|
||||
style: AdaptiveStyle.iOS,
|
||||
context: Get.context!,
|
||||
title: '系统提示',
|
||||
message: '当前群聊不支持邀请用户,请分享群二维码至您要邀请的好友。',
|
||||
okLabel: '去分享',
|
||||
cancelLabel: '取消',
|
||||
defaultType: OkCancelAlertDefaultType.ok,
|
||||
);
|
||||
|
||||
if (result == OkCancelResult.ok) {
|
||||
Get.toNamed(ContactRoutes.groupQrCode);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.unactive.withOpacity(0.1),
|
||||
border: Border.all(
|
||||
color: AppColors.unactive.withOpacity(0.3),
|
||||
width: 0.4,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
'邀请',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (_.currentGroup.value.isAdmin || _.currentGroup.value.isOwner) {
|
||||
items.add(
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ContactRoutes.groupKick,
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.unactive.withOpacity(0.1),
|
||||
border: Border.all(
|
||||
color: AppColors.unactive.withOpacity(0.3),
|
||||
width: 0.4,
|
||||
style: BorderStyle.solid,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
'移除',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: AppColors.white,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: GridView.count(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 5,
|
||||
childAspectRatio: 1 / 1.1,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
children: items,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _memberItem(V2TimGroupMemberFullInfo member) {
|
||||
double w = 40;
|
||||
double h = 12;
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
await PrivateController.to.setCurrentFriend(member.userID);
|
||||
Get.toNamed(
|
||||
ContactRoutes.friendProfile,
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
ClipRRect(
|
||||
child: Stack(
|
||||
children: [
|
||||
CustomAvatar(member.faceUrl),
|
||||
if (member.role ==
|
||||
GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_ADMIN ||
|
||||
member.role ==
|
||||
GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_OWNER)
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: sqrt(w * w / 2 - sqrt2 * w * h + h * h),
|
||||
child: Transform.rotate(
|
||||
angle: -0.25 * pi,
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: Container(
|
||||
color: member.role ==
|
||||
GroupMemberRoleType
|
||||
.V2TIM_GROUP_MEMBER_ROLE_OWNER
|
||||
? AppColors.red
|
||||
: AppColors.golden,
|
||||
width: w,
|
||||
height: h,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
member.role ==
|
||||
GroupMemberRoleType
|
||||
.V2TIM_GROUP_MEMBER_ROLE_OWNER
|
||||
? '群主'
|
||||
: '管理员',
|
||||
style: const TextStyle(
|
||||
color: AppColors.white,
|
||||
fontSize: 8,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
member.nameCard!.isNotEmpty ? member.nameCard! : member.nickName!,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user