2026-07-01 18:25:58 +08:00

443 lines
15 KiB
Dart

import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_debouncer/flutter_debouncer.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../../app_localizations.dart';
import '../../../chatvibe_core/constants/at_room_msg_type.dart';
import '../../../chatvibe_core/constants/at_screen.dart';
import '../../../chatvibe_core/utilities/at_user_utils.dart';
import '../../../chatvibe_data/models/enum/at_room_roles_type.dart';
import '../../../chatvibe_data/sources/local/user_manager.dart';
import '../../../chatvibe_data/sources/repositories/room_repository_imp.dart';
import '../../../chatvibe_domain/models/res/room_member_res.dart';
import '../../../chatvibe_managers/rtc_manager.dart';
import '../../../chatvibe_managers/rtm_manager.dart';
import '../../../chatvibe_ui/components/at_compontent.dart';
import '../../../chatvibe_ui/components/at_page_list.dart';
import '../../../chatvibe_ui/components/at_tts.dart';
import '../../../chatvibe_ui/components/text/at_text.dart';
import '../../../chatvibe_ui/widgets/room/room_msg_item.dart';
///房间成员列表
class RoomMemberPage extends ATPageList {
String? roomId = "";
bool isHomeowner = false;
RoomMemberPage({super.key, this.roomId, this.isHomeowner = false});
@override
_RoomMemberPageState createState() =>
_RoomMemberPageState(roomId, isHomeowner);
}
class _RoomMemberPageState
extends ATPageListState<ChatVibeRoomMemberRes, RoomMemberPage> {
String? roomId = "";
String? lastId;
bool isHomeowner = false;
String optTips = "";
_RoomMemberPageState(this.roomId, this.isHomeowner);
final debouncer = Debouncer();
@override
void initState() {
super.initState();
enablePullUp = true;
enablePullDown = false;
// Cursor pagination: treat only an empty response as "no more data".
pageCount = 1;
backgroundColor = Colors.transparent;
loadData(1);
}
@override
Widget build(BuildContext context) {
optTips = ATAppLocalizations.of(context)!.operationSuccessful;
return ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: SafeArea(
top: false,
child: Container(
decoration: BoxDecoration(
color: Colors.black54,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.w),
topRight: Radius.circular(12.w),
),
),
child: Column(
children: [
SizedBox(height: 15.w),
text(
ATAppLocalizations.of(context)!.roomMember,
fontSize: 14.sp,
textColor: Colors.white,
),
SizedBox(height: 10.w),
SizedBox(height: 350.w, child: buildList(context)),
],
),
),
),
),
);
}
@override
Widget buildItemOne(ChatVibeRoomMemberRes userInfo, int index) {
final bool showRoleTag = _shouldShowRoleTag1(index, userInfo.roles);
return Column(
children: [
if (showRoleTag) buildTag1(userInfo.roles),
if (showRoleTag) SizedBox(height: 3.w),
_buildMemberItem1(userInfo),
],
);
}
bool _shouldShowRoleTag1(int index, String? currentRole) {
if (index == 0) {
return true;
}
return items[index - 1].roles != currentRole;
}
Widget _buildMemberItem1(ChatVibeRoomMemberRes userInfo) {
return GestureDetector(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10.w, vertical: 5.w),
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.w),
color: Colors.white24,
),
child: Row(
children: [
head(
url: userInfo.userProfile?.userAvatar ?? "",
width: 52.w,
headdress: userInfo.userProfile?.getHeaddress()?.sourceUrl,
),
SizedBox(width: 3.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 240.w,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
msgRoleTag(
userInfo.roles ?? "",
width: 20.w,
height: 20.w,
),
SizedBox(width: 3.w),
chatvibeNickNameText(
maxWidth: 160.w,
userInfo.userProfile?.userNickname ?? "",
fontSize: 14.sp,
type: userInfo.userProfile?.getVIP()?.name ?? "",
needScroll:
(userInfo
.userProfile
?.userNickname
?.characters
.length ??
0) >
14,
),
SizedBox(width: 3.w),
userInfo.userProfile?.getVIP() != null
? netImage(
url: userInfo.userProfile?.getVIP()?.cover ?? "",
width: 25.w,
height: 25.w,
)
: Container(),
SizedBox(width: 5.w),
userInfo.userProfile?.wearBadge?.isNotEmpty ?? false
? SizedBox(
height: 25.w,
child: ListView.separated(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount:
userInfo.userProfile?.wearBadge?.length ??
0,
itemBuilder: (context, index) {
return netImage(
width: 25.w,
height: 25.w,
url:
userInfo
.userProfile
?.wearBadge?[index]
.selectUrl ??
"",
);
},
separatorBuilder: (
BuildContext context,
int index,
) {
return SizedBox(width: 5.w);
},
),
)
: Container(),
],
),
),
),
SizedBox(height: 3.w),
GestureDetector(
child: Row(
textDirection: TextDirection.ltr,
children: [
Row(
children: [
getIdIcon(
userInfo.userProfile?.wealthLevel??0,
width: 28.w,
height: 28.w,
textColor: Colors.white,
fontSize: 12.sp,
fontWeight: FontWeight.w600,
),
chatvibeNickNameText(
maxWidth: 135.w,
userInfo.userProfile?.getID() ?? "",
textColor: Colors.white,
fontSize: 12.sp,
fontWeight: FontWeight.w600,
type:
userInfo.userProfile?.getVIP()?.name ?? "",
needScroll:
(userInfo.userProfile
?.getID()
.characters
.length ??
0) >
13,
),
],
)
,
],
),
onTap: () {
Clipboard.setData(
ClipboardData(text: userInfo.userProfile?.getID() ?? ""),
);
ATTts.show(
ATAppLocalizations.of(context)!.copiedToClipboard,
);
},
),
],
),
Spacer(),
userInfo.roles != ATRoomRolesType.HOMEOWNER.name && isHomeowner
? GestureDetector(
child: Image.asset(
"atu_images/room/at_icon_remve_block.png",
width: 20.w,
height: 20.w,
),
onTap: () {
debouncer.debounce(
duration: Duration(milliseconds: 500),
onDebounce: () {
ChatRoomRepository()
.changeRoomRole(
roomId ?? "",
ATRoomRolesType.TOURIST.name,
userInfo.userProfile?.id ?? "",
AccountStorage()
.getCurrentUser()
?.userProfile
?.id ??
"",
"OTHER_CHANGE",
)
.whenComplete(() {
ATTts.show(optTips);
Msg msg = Msg(
groupId:
Provider.of<RealTimeCommunicationManager>(
context,
listen: false,
)
.currenRoom
?.roomProfile
?.roomProfile
?.roomAccount,
msg: 'TOURIST',
toUser: userInfo.userProfile,
type: ATRoomMsgType.roomRoleChange,
);
Provider.of<RealTimeMessagingManager>(
context,
listen: false,
).sendMsg(msg, addLocal: true);
Navigator.of(context).pop();
});
},
);
},
)
: Container(),
],
),
),
onTap: () {
Navigator.of(context).pop();
num index = Provider.of<RealTimeCommunicationManager>(
context,
listen: false,
).userOnMaiInIndex(userInfo.id ?? "");
Provider.of<RealTimeCommunicationManager>(
context,
listen: false,
).clickSite(index, clickUser: userInfo.userProfile);
},
);
}
@override
empty() {
List<Widget> list = [];
list.add(SizedBox(height: height(30)));
list.add(Image.asset('atu_images/general/at_icon_loading.png'));
list.add(SizedBox(height: height(15)));
list.add(
Text(
ATAppLocalizations.of(context)!.noData,
style: TextStyle(
fontSize: sp(14),
color: Color(0xff999999),
fontWeight: FontWeight.w400,
decoration: TextDecoration.none,
height: 1,
),
),
);
return Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: list,
);
}
@override
builderDivider() {
// return Divider(
// height: 1.w,
// color: Color(0xff3D3277).withOpacity(0.5),
// indent: 15.w,
// );
return Container(height: 8.w);
}
///加载数据
@override
loadPage({
required int page,
required Function(List<ChatVibeRoomMemberRes>) onSuccess,
Function? onErr,
}) async {
if (page == 1) {
lastId = null;
}
if ((roomId ?? "").isEmpty) {
onSuccess([]);
return;
}
try {
final userList = await ChatRoomRepository().roomMember(
roomId ?? "",
lastId: lastId,
);
final deduplicated = userList.where((user) => user.id != lastId).toList();
final visibleList =
deduplicated
.where(
(user) =>
user.roles == ATRoomRolesType.HOMEOWNER.name ||
user.roles == ATRoomRolesType.ADMIN.name ||
user.roles == ATRoomRolesType.MEMBER.name,
)
.toList();
if (deduplicated.isNotEmpty) {
lastId = deduplicated.last.id;
}
onSuccess(visibleList);
} catch (e) {
onErr?.call();
}
}
Widget buildTag1(String? roles) {
if (roles == ATRoomRolesType.HOMEOWNER.name) {
return Row(
children: [
SizedBox(width: 5.w),
text(
ATAppLocalizations.of(context)!.owner,
fontSize: 13.sp,
textColor: Colors.white54,
),
Spacer(),
],
);
} else if (roles == ATRoomRolesType.ADMIN.name) {
return Row(
children: [
SizedBox(width: 5.w),
text(
ATAppLocalizations.of(context)!.admin,
fontSize: 13.sp,
textColor: Colors.white54,
),
Spacer(),
// Image.asset(
// "images/room/icon_add_user.png",
// width: 25.w,
// height: 25.w,
// ),
// SizedBox(width: 3.w),
],
);
} else if (roles == ATRoomRolesType.MEMBER.name) {
return Row(
children: [
SizedBox(width: 5.w),
text(
ATAppLocalizations.of(context)!.member,
fontSize: 13.sp,
textColor: Colors.white54,
),
Spacer(),
// Image.asset(
// "images/room/icon_add_user.png",
// width: 25.w,
// height: 25.w,
// ),
// SizedBox(width: 3.w),
],
);
}
return Container();
}
}