feat: 群组信息自定义
This commit is contained in:
@@ -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<StatefulWidget> createState() => _TIMUIKitGroupState();
|
||||
|
||||
/// 刷新群组列表数据的静态方法
|
||||
/// Static method to refresh group list data
|
||||
static void refreshGroupListData(GlobalKey<TIMUIKitGroupState> key) {
|
||||
key.currentState?.refreshGroupListData();
|
||||
}
|
||||
}
|
||||
|
||||
class _TIMUIKitGroupState extends TIMUIKitState<TIMUIKitGroup> {
|
||||
final TUIFriendShipViewModel _friendshipViewModel = serviceLocator<TUIFriendShipViewModel>();
|
||||
final TUIGroupListenerModel _groupListenerModel = serviceLocator<TUIGroupListenerModel>();
|
||||
final TUIFriendShipViewModel _friendshipViewModel =
|
||||
serviceLocator<TUIFriendShipViewModel>();
|
||||
final TUIGroupListenerModel _groupListenerModel =
|
||||
serviceLocator<TUIGroupListenerModel>();
|
||||
|
||||
List<ISuspensionBeanImpl<V2TimGroupInfo>> _getShowList(List<V2TimGroupInfo> groupList) {
|
||||
final List<ISuspensionBeanImpl<V2TimGroupInfo>> showList = List.empty(growable: true);
|
||||
/// 刷新群组列表数据
|
||||
/// Refresh group list data
|
||||
void refreshGroupListData() {
|
||||
_friendshipViewModel.loadGroupListData();
|
||||
}
|
||||
|
||||
List<ISuspensionBeanImpl<V2TimGroupInfo>> _getShowList(
|
||||
List<V2TimGroupInfo> groupList,
|
||||
) {
|
||||
final List<ISuspensionBeanImpl<V2TimGroupInfo>> 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<TIMUIKitGroup> {
|
||||
final theme = Provider.of<TUIThemeViewModel>(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<TIMUIKitGroup> {
|
||||
);
|
||||
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<TIMUIKitGroup> {
|
||||
),
|
||||
),
|
||||
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<TIMUIKitGroup> {
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: _friendshipViewModel),
|
||||
ChangeNotifierProvider.value(value: _groupListenerModel),
|
||||
ChangeNotifierProvider.value(value: serviceLocator<TUIThemeViewModel>()),
|
||||
ChangeNotifierProvider.value(
|
||||
value: serviceLocator<TUIThemeViewModel>(),
|
||||
),
|
||||
],
|
||||
builder: (BuildContext context, Widget? w) {
|
||||
final NeedUpdate? needUpdate = Provider.of<TUIGroupListenerModel>(context).needUpdate;
|
||||
final NeedUpdate? needUpdate = Provider.of<TUIGroupListenerModel>(
|
||||
context,
|
||||
).needUpdate;
|
||||
if (needUpdate != null) {
|
||||
_groupListenerModel.needUpdate = null;
|
||||
switch (needUpdate.updateType) {
|
||||
@@ -156,20 +200,23 @@ class _TIMUIKitGroupState extends TIMUIKitState<TIMUIKitGroup> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<V2TimGroupInfo> groupList = Provider.of<TUIFriendShipViewModel>(context).groupList;
|
||||
List<V2TimGroupInfo> groupList = Provider.of<TUIFriendShipViewModel>(
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user