ChannelList / ChannelSwitcher
Flutter IMKit 提供两个频道组件:ChannelList(频道列表/选择,含创建/加入/离开)与 ChannelSwitcher(聊天页顶部入口,点击弹出列表)。ChatView 在超级群会话下默认自动挂载切换器。
运行时组件(非 IDL 契约)
本组件由 SDK 运行时直接提供,不是 IDL 契约组件:IMKit 契约(sdk-imkit)只声明 10 个契约组件(ConversationListView / ChatView / MessageBubble / MessageInput / Avatar / UnreadBadge / TimeSeparator / MessageStatusIndicator / Theme / IMKitFacade),不包含当前版本频道 UI 组件;因此下面的 props/事件以各端实际实现为准,跨端命名不保证一致。
最小示例
Dart
// 1) 聊天页:交给 ChatView 自动挂载(仅 SUPER_GROUP 且注入 controller 时)
ChatView(
client: client,
conversationType: RongIMConversationType.SUPER_GROUP,
targetId: 'g_1001',
channelId: 'ch_news',
currentUserId: me,
)
// 2) 或者自己使用 ChannelSwitcher(可替换 ChatView 的默认入口)
ChannelSwitcher(
client: client,
groupId: 'g_1001',
currentChannelId: 'ch_news',
currentUserId: me,
onSelect: (channel) => setState(() => channelId = channel?.channelId),
)
// 3) 独立频道列表(页面/弹窗)
ChannelList(
client: client,
groupId: 'g_1001',
currentChannelId: 'ch_news',
currentUserId: me,
onSelect: (channel) => Navigator.pop(context, channel),
)ChannelList Props
| Prop | 类型 | 说明 |
|---|---|---|
| groupId | String | 超级群 ID(必填) |
| client | RCIMIWEngine? | 注入后组件内部调用 IMLib(列表/创建/加入/离开) |
| loadChannels | ChannelListLoader? | 自定义加载器(Future),测试/宿主接管网络 |
| currentChannelId | String? | 当前频道;null/空 = 群级消息 |
| currentUserId | String? | 判断是否已加入(userIds 包含) |
| showGroupLevelOption | bool | 是否显示「群级消息」选项 |
| theme | ImkitTheme? | 缺省 ImkitTheme.of(context),跟随 light/dark |
| onSelect | ValueChanged | 选择频道(null = 群级) |
| onCreate / onJoin / onLeave | 回调 | 提供时由宿主接管;未提供且注入 client 时组件内部调用 IMLib |
ChannelSwitcher Props
| Prop | 类型 | 说明 |
|---|---|---|
| groupId | String | 超级群 ID |
| client / loadChannels | 同上 | 数据来源 |
| currentChannelId / currentChannelName | String? | 当前频道;name 缺省时显示 ID |
| currentUserId | String? | 传给内部 ChannelList 判断已加入 |
| theme | ImkitTheme? | 底部弹层与入口行配色 |
| onSelect / onCreate / onJoin / onLeave | 回调 | 透传给 ChannelList |
ChatView 集成
当 controller != null 且 conversationType = RongIMConversationType.SUPER_GROUP 时,ChatView 自动在消息流上方挂载 ChannelSwitcher 并调用 controller.switchChannel(channelId);宿主可用 channelSwitcher prop 替换为自定义入口。
主题与测试钩子
- 颜色全部取自
ImkitTheme(background/surface/text/textSecondary/primary/danger),light/dark 自动适配。 - 稳定 Key:
ValueKey("channel-switcher")、ValueKey("channel-switcher-label"),便于 widget test。 loadChannels可注入假数据,避免测试依赖网络。- 文案为中文(群级消息 / 频道 / 公开 / 私有 / 加入 / 离开);未提供 locale 参数。
限制
- 不提供频道成员管理(成员增删用 IMLib/Server API)。
- 创建频道仅名称(public/private 由组件内建调用选择),不支持自定义 joinPolicy。
- 频道级未读/回执未拆分;切换频道后未读仍按群会话统计。