diff --git a/lib/ui/views/TIMUIKitGroup/tim_uikit_group.dart b/lib/ui/views/TIMUIKitGroup/tim_uikit_group.dart index 636de5e..70c2868 100644 --- a/lib/ui/views/TIMUIKitGroup/tim_uikit_group.dart +++ b/lib/ui/views/TIMUIKitGroup/tim_uikit_group.dart @@ -18,29 +18,57 @@ import 'package:tencent_cloud_chat_uikit/base_widgets/tim_ui_kit_base.dart'; import 'package:tencent_cloud_chat_uikit/theme/color.dart'; import 'package:tencent_cloud_chat_uikit/theme/tui_theme_view_model.dart'; -typedef GroupItemBuilder = Widget Function(BuildContext context, V2TimGroupInfo groupInfo); +typedef GroupItemBuilder = + Widget Function(BuildContext context, V2TimGroupInfo groupInfo); + +/// TIMUIKitGroup State的类型定义,用于外部引用 +typedef TIMUIKitGroupState = _TIMUIKitGroupState; class TIMUIKitGroup extends StatefulWidget { - final void Function(V2TimGroupInfo groupInfo, V2TimConversation conversation)? onTapItem; + final void Function(V2TimGroupInfo groupInfo, V2TimConversation conversation)? + onTapItem; final Widget Function(BuildContext context)? emptyBuilder; final GroupItemBuilder? itemBuilder; /// the filter for group conversation final bool Function(V2TimGroupInfo? groupInfo)? groupCollector; - const TIMUIKitGroup({Key? key, this.onTapItem, this.emptyBuilder, this.itemBuilder, this.groupCollector}) - : super(key: key); + const TIMUIKitGroup({ + Key? key, + this.onTapItem, + this.emptyBuilder, + this.itemBuilder, + this.groupCollector, + }) : super(key: key); @override State createState() => _TIMUIKitGroupState(); + + /// 刷新群组列表数据的静态方法 + /// Static method to refresh group list data + static void refreshGroupListData(GlobalKey key) { + key.currentState?.refreshGroupListData(); + } } class _TIMUIKitGroupState extends TIMUIKitState { - final TUIFriendShipViewModel _friendshipViewModel = serviceLocator(); - final TUIGroupListenerModel _groupListenerModel = serviceLocator(); + final TUIFriendShipViewModel _friendshipViewModel = + serviceLocator(); + final TUIGroupListenerModel _groupListenerModel = + serviceLocator(); - List> _getShowList(List groupList) { - final List> showList = List.empty(growable: true); + /// 刷新群组列表数据 + /// Refresh group list data + void refreshGroupListData() { + _friendshipViewModel.loadGroupListData(); + } + + List> _getShowList( + List groupList, + ) { + final List> showList = List.empty( + growable: true, + ); for (var i = 0; i < groupList.length; i++) { final item = groupList[i]; @@ -63,10 +91,16 @@ class _TIMUIKitGroupState extends TIMUIKitState { final theme = Provider.of(context).theme; final showName = groupInfo.groupName ?? groupInfo.groupID; final faceUrl = groupInfo.faceUrl ?? ""; - final isDesktopScreen = TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; + final isDesktopScreen = + TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; return Container( decoration: BoxDecoration( - border: Border(bottom: BorderSide(color: theme.weakDividerColor ?? CommonColor.weakDividerColor))), + border: Border( + bottom: BorderSide( + color: theme.weakDividerColor ?? CommonColor.weakDividerColor, + ), + ), + ), child: Material( color: isDesktopScreen ? theme.wideBackgroundColor : null, child: InkWell( @@ -82,7 +116,9 @@ class _TIMUIKitGroupState extends TIMUIKitState { ); final res = await TencentImSDKPlugin.v2TIMManager .getConversationManager() - .getConversation(conversationID: "group_${groupInfo.groupID}"); + .getConversation( + conversationID: "group_${groupInfo.groupID}", + ); if (res.code == 0 && res.data != null) { conversation = res.data!; } @@ -107,14 +143,18 @@ class _TIMUIKitGroupState extends TIMUIKitState { ), ), Expanded( - child: Container( - alignment: Alignment.centerLeft, - padding: const EdgeInsets.only(top: 10, bottom: 20), - child: Text( - showName, - style: TextStyle(color: Colors.black, fontSize: isDesktopScreen ? 14 : 18), + child: Container( + alignment: Alignment.centerLeft, + padding: const EdgeInsets.only(top: 10, bottom: 20), + child: Text( + showName, + style: TextStyle( + color: Colors.black, + fontSize: isDesktopScreen ? 14 : 18, + ), + ), ), - )) + ), ], ), ), @@ -139,10 +179,14 @@ class _TIMUIKitGroupState extends TIMUIKitState { providers: [ ChangeNotifierProvider.value(value: _friendshipViewModel), ChangeNotifierProvider.value(value: _groupListenerModel), - ChangeNotifierProvider.value(value: serviceLocator()), + ChangeNotifierProvider.value( + value: serviceLocator(), + ), ], builder: (BuildContext context, Widget? w) { - final NeedUpdate? needUpdate = Provider.of(context).needUpdate; + final NeedUpdate? needUpdate = Provider.of( + context, + ).needUpdate; if (needUpdate != null) { _groupListenerModel.needUpdate = null; switch (needUpdate.updateType) { @@ -156,20 +200,23 @@ class _TIMUIKitGroupState extends TIMUIKitState { break; } } - List groupList = Provider.of(context).groupList; + List groupList = Provider.of( + context, + ).groupList; if (widget.groupCollector != null) { groupList = groupList.where(widget.groupCollector!).toList(); } if (groupList.isNotEmpty) { final showList = _getShowList(groupList); return AZListViewContainer( - isShowIndexBar: false, - memberList: showList, - itemBuilder: (context, index) { - final groupInfo = showList[index].memberInfo; - final itemBuilder = _getItemBuilder(); - return itemBuilder(context, groupInfo); - }); + isShowIndexBar: false, + memberList: showList, + itemBuilder: (context, index) { + final groupInfo = showList[index].memberInfo; + final itemBuilder = _getItemBuilder(); + return itemBuilder(context, groupInfo); + }, + ); } if (widget.emptyBuilder != null) { diff --git a/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_member_title.dart b/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_member_title.dart index fcc843f..aadaad3 100644 --- a/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_member_title.dart +++ b/lib/ui/views/TIMUIKitGroupProfile/widgets/tim_uikit_group_member_title.dart @@ -20,8 +20,13 @@ import 'package:tencent_cloud_chat_uikit/theme/color.dart'; import 'package:tencent_cloud_chat_uikit/theme/tui_theme.dart'; class GroupMemberTitle extends TIMUIKitStatelessWidget { + final VoidCallback? onAddMemberPressed; + final VoidCallback? onRemoveMemberPressed; + GroupMemberTitle({ Key? key, + this.onAddMemberPressed, + this.onRemoveMemberPressed, }) : super(key: key); List _getMemberList(memberList, int showRange) { @@ -40,8 +45,14 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { return friendRemark != "" ? friendRemark : showName; } - List _groupMemberListBuilder(List memberList, TUITheme theme, TUIGroupProfileModel model, int showRange) { - final isDesktopScreen = TUIKitScreenUtils.getFormFactor() == DeviceType.Desktop; + List _groupMemberListBuilder( + List memberList, + TUITheme theme, + TUIGroupProfileModel model, + int showRange, + ) { + final isDesktopScreen = + TUIKitScreenUtils.getFormFactor() == DeviceType.Desktop; return _getMemberList(memberList, showRange).map((element) { final faceUrl = element?.faceUrl ?? ""; final showName = _getShowName(element); @@ -61,22 +72,25 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { width: isDesktopScreen ? 36 : 50, height: isDesktopScreen ? 36 : 50, child: Avatar( - borderRadius: isDesktopScreen ? BorderRadius.circular(18) : null, + borderRadius: isDesktopScreen + ? BorderRadius.circular(18) + : null, faceUrl: faceUrl, showName: showName, type: 1, ), ), - if (!isDesktopScreen) - const SizedBox( - height: 8, - ), + if (!isDesktopScreen) const SizedBox(height: 8), if (!isDesktopScreen) Text( showName, textAlign: TextAlign.center, - style: TextStyle(overflow: TextOverflow.ellipsis, color: theme.weakTextColor, fontSize: 10), - ) + style: TextStyle( + overflow: TextOverflow.ellipsis, + color: theme.weakTextColor, + fontSize: 10, + ), + ), ], ), ), @@ -84,35 +98,51 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { }).toList(); } - List _inviteMemberBuilder(bool isCanInviteMember, bool isCanKickOffMember, theme, BuildContext context) { + List _inviteMemberBuilder( + bool isCanInviteMember, + bool isCanKickOffMember, + theme, + BuildContext context, + ) { return []; } void navigateToMemberList( - BuildContext context, TUIGroupProfileModel model, List memberList) { - final isDesktopScreen = TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; + BuildContext context, + TUIGroupProfileModel model, + List memberList, + ) { + final isDesktopScreen = + TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; if (!isDesktopScreen) { Navigator.push( - context, - MaterialPageRoute( - builder: (context) => GroupProfileMemberListPage(model: model, memberList: memberList), - )); + context, + MaterialPageRoute( + builder: (context) => + GroupProfileMemberListPage(model: model, memberList: memberList), + ), + ); } else { final option1 = memberList.length.toString(); TUIKitWidePopup.showPopupWindow( - operationKey: TUIKitWideModalOperationKey.groupMembersList, - context: context, - width: MediaQuery.of(context).size.width * 0.5, - height: MediaQuery.of(context).size.height * 0.8, - title: TIM_t_para("群成员({{option1}}人)", "群成员($option1人)")(option1: option1), - child: (onClose) => GroupProfileMemberListPage(model: model, memberList: memberList)); + operationKey: TUIKitWideModalOperationKey.groupMembersList, + context: context, + width: MediaQuery.of(context).size.width * 0.5, + height: MediaQuery.of(context).size.height * 0.8, + title: TIM_t_para("群成员({{option1}}人)", "群成员($option1人)")( + option1: option1, + ), + child: (onClose) => + GroupProfileMemberListPage(model: model, memberList: memberList), + ); } } @override Widget tuiBuild(BuildContext context, TUIKitBuildValue value) { final TUITheme theme = value.theme; - final isDesktopScreen = TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; + final isDesktopScreen = + TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop; final model = Provider.of(context); final memberAmount = model.groupInfo?.memberCount ?? 0; final option1 = memberAmount.toString(); @@ -139,7 +169,14 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { decoration: isDesktopScreen ? null : BoxDecoration( - border: Border(bottom: BorderSide(color: theme.weakDividerColor ?? CommonColor.weakDividerColor))), + border: Border( + bottom: BorderSide( + color: + theme.weakDividerColor ?? + CommonColor.weakDividerColor, + ), + ), + ), child: InkWell( onTap: () async { navigateToMemberList(context, model, memberList); @@ -147,19 +184,30 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text(TIM_t("群成员"), style: TextStyle(color: theme.darkTextColor, fontSize: isDesktopScreen ? 14 : 16)), + Text( + TIM_t("群成员"), + style: TextStyle( + color: theme.darkTextColor, + fontSize: isDesktopScreen ? 14 : 16, + ), + ), Row( children: [ Text( - TIM_t_para("{{option1}}人", "$option1人")(option1: option1), - style: TextStyle(color: theme.darkTextColor, fontSize: isDesktopScreen ? 14 : 16), + TIM_t_para("{{option1}}人", "$option1人")( + option1: option1, + ), + style: TextStyle( + color: theme.darkTextColor, + fontSize: isDesktopScreen ? 14 : 16, + ), ), Icon( Icons.keyboard_arrow_right, color: theme.weakTextColor, ), ], - ) + ), ], ), ), @@ -171,25 +219,30 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { }, child: Container( decoration: BoxDecoration( - border: Border.all(width: 1, color: theme.weakDividerColor ?? CommonColor.weakDividerColor), + border: Border.all( + width: 1, + color: + theme.weakDividerColor ?? CommonColor.weakDividerColor, + ), borderRadius: const BorderRadius.all(Radius.circular(4)), ), // height: 30, - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6), + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 6, + ), child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - Icon( - Icons.search, - color: hexToColor("979797"), - size: 16, - ), + Icon(Icons.search, color: hexToColor("979797"), size: 16), const SizedBox(width: 6), - Text(TIM_t("搜索"), - style: TextStyle( - color: theme.weakTextColor, - fontSize: 12, - )), + Text( + TIM_t("搜索"), + style: TextStyle( + color: theme.weakTextColor, + fontSize: 12, + ), + ), ], ), ), @@ -205,67 +258,76 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { ..._groupMemberListBuilder(memberList, theme, model, showRange), if (isCanInviteMember) DottedBorder( - borderType: BorderType.RRect, - radius: Radius.circular(isDesktopScreen ? 18 : 4.5), - color: theme.weakTextColor!, - dashPattern: const [6, 3], - child: SizedBox( - width: isDesktopScreen ? 32 : 48, - height: isDesktopScreen ? 32 : 48, - child: IconButton( - onPressed: () { + borderType: BorderType.RRect, + radius: Radius.circular(isDesktopScreen ? 18 : 4.5), + color: theme.weakTextColor!, + dashPattern: const [6, 3], + child: SizedBox( + width: isDesktopScreen ? 32 : 48, + height: isDesktopScreen ? 32 : 48, + child: IconButton( + onPressed: () { + if (onAddMemberPressed != null) { + onAddMemberPressed!(); + } else { if (isDesktopScreen) { TUIKitWidePopup.showPopupWindow( - context: context, - operationKey: TUIKitWideModalOperationKey.addGroupMembers, - width: 350, - title: TIM_t("添加群成员"), - height: 460, - onSubmit: () { - addGroupMemberKey.currentState?.submitAdd(); - }, - child: (onClose) => AddGroupMemberPage( - model: model, - onClose: onClose, - key: addGroupMemberKey, - )); + context: context, + operationKey: + TUIKitWideModalOperationKey.addGroupMembers, + width: 350, + title: TIM_t("添加群成员"), + height: 460, + onSubmit: () { + addGroupMemberKey.currentState?.submitAdd(); + }, + child: (onClose) => AddGroupMemberPage( + model: model, + onClose: onClose, + key: addGroupMemberKey, + ), + ); } else { Navigator.push( - context, - MaterialPageRoute( - builder: (context) => AddGroupMemberPage( - model: model, - ), - )); + context, + MaterialPageRoute( + builder: (context) => + AddGroupMemberPage(model: model), + ), + ); } - }, - icon: Icon( - Icons.add, - size: isDesktopScreen ? 16 : 18, - ), - color: theme.weakTextColor, - ), - )), + } + }, + icon: Icon(Icons.add, size: isDesktopScreen ? 16 : 18), + color: theme.weakTextColor, + ), + ), + ), if (isCanKickOffMember) DottedBorder( - borderType: BorderType.RRect, - radius: Radius.circular(isDesktopScreen ? 18 : 4.5), - color: theme.weakTextColor!, - dashPattern: const [6, 3], - child: SizedBox( - width: isDesktopScreen ? 32 : 48, - height: isDesktopScreen ? 32 : 48, - child: IconButton( - onPressed: () { + borderType: BorderType.RRect, + radius: Radius.circular(isDesktopScreen ? 18 : 4.5), + color: theme.weakTextColor!, + dashPattern: const [6, 3], + child: SizedBox( + width: isDesktopScreen ? 32 : 48, + height: isDesktopScreen ? 32 : 48, + child: IconButton( + onPressed: () { + if (onRemoveMemberPressed != null) { + onRemoveMemberPressed!(); + } else { if (isDesktopScreen) { TUIKitWidePopup.showPopupWindow( - operationKey: TUIKitWideModalOperationKey.kickOffGroupMembers, + operationKey: TUIKitWideModalOperationKey + .kickOffGroupMembers, context: context, width: 350, title: TIM_t("删除群成员"), height: 460, onSubmit: () { - deleteGroupMemberKey.currentState?.submitDelete(); + deleteGroupMemberKey.currentState + ?.submitDelete(); }, child: (onClose) => DeleteGroupMemberPage( model: model, @@ -275,19 +337,23 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { ); } else { Navigator.push( - context, - MaterialPageRoute( - builder: (context) => DeleteGroupMemberPage(model: model), - )); + context, + MaterialPageRoute( + builder: (context) => + DeleteGroupMemberPage(model: model), + ), + ); } - }, - icon: Icon( - Icons.remove, - size: isDesktopScreen ? 16 : 18, - ), - color: theme.weakTextColor, + } + }, + icon: Icon( + Icons.remove, + size: isDesktopScreen ? 16 : 18, ), - )), + color: theme.weakTextColor, + ), + ), + ), ], ), ), @@ -298,7 +364,10 @@ class GroupMemberTitle extends TIMUIKitStatelessWidget { margin: EdgeInsets.only(top: isDesktopScreen ? 12 : 16), child: Text( TIM_t("查看更多群成员"), - style: TextStyle(color: theme.weakTextColor, fontSize: isDesktopScreen ? 12 : 14), + style: TextStyle( + color: theme.weakTextColor, + fontSize: isDesktopScreen ? 12 : 14, + ), ), ), onTap: () async { diff --git a/pubspec.yaml b/pubspec.yaml index b038d42..a5114bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: tencent_cloud_chat_uikit description: A powerful chat UI component library and business logic for Tencent Cloud Chat, creating seamless in-app chat modules for delightful user experiences. -version: 5.0.1 +version: 5.0.2 homepage: https://trtc.io/products/chat?utm_source=gfs&utm_medium=link&utm_campaign=%E6%B8%A0%E9%81%93&_channel_track_key=k6WgfCKn repository: https://github.com/TencentCloud/chat-uikit-flutter documentation: https://comm.qq.com/im/doc/flutter/en/TUIKit/readme.html