会话列表(Config 部分自定义 UI)
会话列表通过 RCKConvoConfig 进行部分自定义 UI,覆盖 AppBar、头像、标题、最后一条消息、时间、未读角标、免打扰图标、单元格样式、元素布局、侧滑操作、整体列表等。以下为所有可用配置及字段说明,并提供常见使用示例。
入口组件
- 组件:
RCKConvoPage - 配置:
RCKConvoConfig
总览:RCKConvoConfig(会话列表整体配置)
包含以下子配置:
appBarConfig: 顶部导航栏配置(详见下文“AppBar 配置”)avatarConfig: 头像配置titleConfig: 标题(会话名)配置lastMessageConfig: 最后一条消息配置timeConfig: 时间配置unreadBadgeConfig: 未读角标配置muteIconConfig: 免打扰图标配置itemConfig: 单元格容器与分割线配置layoutConfig: 各元素在单元格内的布局位置与间距slidableConfig: 侧滑操作配置(置顶/删除/免打扰/自定义)listConfig: 列表级别配置(搜索、分页、背景等)
AppBar 配置(RCKConvoAppBarConfig)
height(double): AppBar 高度padding(EdgeInsets): AppBar 内边距centerTitle(bool): 标题是否居中automaticallyImplyLeading(bool): 是否自动添加返回按钮backgroundConfig(BackgroundConfig): 背景(颜色/图片/渐变/边框/圆角/阴影)leadingConfig(LeadingConfig): 左侧区域(图标/文本/点击/内边距/最大宽度等)titleConfig(AppbarTitleConfig): 标题文本、样式、前后缀图标、间距、内边距、对齐actionsConfig(ActionsConfig): 右侧操作项列表、间距、内边距、对齐
BackgroundConfig 字段:color、image(DecorationImage)、gradient、border、borderRadius、boxShadow
LeadingConfig 字段:icon(Widget?)、text(String?)、textStyle、textOverflow、spacing、onPressed、padding、maxWidth
AppbarTitleConfig 字段:text、textStyle、textOverflow、prefixIcon、suffixIcon、spacing、padding、maxWidth、alignment(MainAxisAlignment)
ActionsConfig 字段:items(List<ActionItem>)、spacing、padding、maxWidth、alignment
ActionItem 字段:icon(Widget,必填)、text、textStyle、textOverflow、spacing、onPressed、padding
示例 :
RCKConvoPage(
config: RCKConvoConfig(
appBarConfig: RCKConvoAppBarConfig(
titleConfig: AppbarTitleConfig(text: '会话'),
leadingConfig: LeadingConfig(
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context),
),
actionsConfig: ActionsConfig(items: [
ActionItem(icon: const Icon(Icons.add), onPressed: () {/* ... */}),
]),
),
),
)
头像配置(RCKAvatarConfig)
shape(AvatarShape): 头像形状。可选:circle、rectangle、roundedRectsize(double): 头像尺寸(有效范围 32–64)borderRadius(double): 圆角大小(shape 为roundedRect时生效)borderColor(Color?): 边框颜色borderWidth(double?): 边框宽度backgroundColor(Color?): 头像背景色badgeOffset(Offset?): 未读角标相对头像的偏移
示例:
avatarConfig: const RCKAvatarConfig(
shape: AvatarShape.circle,
size: 48,
)
标题配置(RCKConvoTitleConfig)
fontSize(double): 字体大小color(Color?): 字体颜色fontWeight(FontWeight): 字重maxLines(int): 最大行数showSuffix(bool): 是否展示标题后缀suffixIcon(IconData?): 后缀图标suffixText(String?): 后缀文本suffixTextStyle(TextStyle?): 后缀文本样式
示例:
titleConfig: const RCKConvoTitleConfig(fontSize: 16, maxLines: 1)
最后一条消息配置(RCKLastMessageConfig)
fontSize(double): 字体大小color(Color): 字体颜色fontWeight(FontWeight): 字重maxLines(int): 最大行数customTypeText(Map<Type, String>?): 自定义消息类型提示文案(覆盖默认映射)
默认映射示例:图片/语音/位置/文件/视频/GIF/撤回 等类型会显示为类似"[图片]""[语音]"等文案
示例:
lastMessageConfig: RCKLastMessageConfig(
maxLines: 1,
customTypeText: const { /* Type → 文案 */ },
)
时间配置(RCKTimeConfig)
fontSize(double): 字体大小color(Color): 颜色fontWeight(FontWeight): 字重formatter(String Function(int timestamp)?): 自定义时间格式化器
示例:
timeConfig: RCKTimeConfig(
formatter: (ts) => DateTime.fromMillisecondsSinceEpoch(ts).toString(),
)
未读角标配置(RCKUnreadBadgeConfig)
backgroundColor(Color): 未读角标背景色muteBackgroundColor(Color): 免打扰时背景色textColor(Color): 文本颜色fontSize(double): 字体大小position(BadgePosition): 显示位置。可选:avatarTopRight(头像右上)、itemRight(单元格右侧)width(double): 宽度(默认约 42)height(double): 高度(默认约 21)overflowText(String): 超过 99 的显示文本(默认99+)
示例:
unreadBadgeConfig: const RCKUnreadBadgeConfig(
position: BadgePosition.itemRight,
)
免打扰图标配置(RCKMuteIconConfig)
show(bool): 是否显示免打扰图标icon(String): 图标资源路径(默认取主题图标)size(double): 图标大小(默认约 16)color(Color): 图标颜色(默认取主题颜色)position(MuteIconPosition): 位置。titleSuffix(标题后缀)、titlePrefix、avatarTopRight、messagePrefix
示例:
muteIconConfig: const RCKMuteIconConfig(show: true)
单元格样式配置(RCKItemConfig)
height(double): 单元格高度(默认 约 76)backgroundColor(Color?): 背景色pinnedBackgroundColor(Color?): 置顶背景色dividerColor(Color?): 分割线颜色dividerIndent(double): 分割线左缩进dividerEndIndent(double): 分割线右缩进dividerHeight(double): 分割线高度(默认约 1)padding(EdgeInsets): 单元格内边距(默认左右含一定内边距)cellSpacing(double): 单元格之间额外间距
示例:
itemConfig: const RCKItemConfig(
height: 72,
dividerColor: Color(0xFFEFEFEF),
)
元素布局配置(RCKLayoutConfig)
avatarPosition(ItemElementPosition): 头像位置titlePosition(ItemElementPosition): 标题位置messagePosition(ItemElementPosition): 消息位置timePosition(ItemElementPosition): 时间位置unreadPosition(ItemElementPosition): 未读角标位置horizontalSpacing(double): 元素水平间距(默认约 16)verticalSpacingEnd(double): 尾部元素垂直间距(默认约 8)verticalSpacingContent(double): 标题与内容竖向间距(默认约 4)
ItemElementPosition 可选:left、right、topLeft、topRight、bottomLeft、bottomRight、center、topRightCorner、bottomRightCorner、avatarTopRight
示例:
layoutConfig: const RCKLayoutConfig(
horizontalSpacing: 16,
unreadPosition: ItemElementPosition.itemRight,
)
侧滑操作配置(RCKSlidableConfig / RCKSlidableActionConfig)
enabled(bool): 是否启用侧滑actions(List<RCKSlidableActionConfig>): 操作按钮,建议 1–3 个
RCKSlidableActionConfig 字段:
label(String): 文本iconPath(String): 图标路径undoIconPath(String?): 撤销图标路径(用于"置顶/取消置顶"等)backgroundColor(Color): 背景色foregroundColor(Color): 前景(文字/图标)颜色actionType(SlidableActionType): 动作类型(pin/delete/mute/custom)autoClose(bool): 点击后是否自动收起侧滑
预置操作构造:RCKSlidableActionConfig.pin()、delete()、mute()
示例:
slidableConfig: RCKSlidableConfig(
actions: [
RCKSlidableActionConfig.pin(),
RCKSlidableActionConfig.delete(),
// RCKSlidableActionConfig.mute(),
],
)
列表配置(RCKListConfig)
showSearchBar(bool): 是否显示搜索框emptyText(String): 空列表提示文案(默认"暂无消息")enablePullToRefresh(bool): 是否支持下拉刷新pageSize(int): 分页大小(默认 20)backgroundColor(Color?): 列表背景色
示例:
listConfig: const RCKListConfig(
showSearchBar: true,
pageSize: 20,
)
综合示例(推荐起步配置)
RCKConvoPage(
config: RCKConvoConfig(
appBarConfig: RCKConvoAppBarConfig(
titleConfig: AppbarTitleConfig(text: '会话'),
),
avatarConfig: const RCKAvatarConfig(shape: AvatarShape.circle, size: 48),
titleConfig: const RCKConvoTitleConfig(fontSize: 16, maxLines: 1),
lastMessageConfig: RCKLastMessageConfig(maxLines: 1),
timeConfig: RCKTimeConfig(),
unreadBadgeConfig: const RCKUnreadBadgeConfig(position: BadgePosition.itemRight),
muteIconConfig: const RCKMuteIconConfig(show: true),
itemConfig: const RCKItemConfig(height: 72),
layoutConfig: const RCKLayoutConfig(horizontalSpacing: 16),
slidableConfig: RCKSlidableConfig(actions: [
RCKSlidableActionConfig.pin(),
RCKSlidableActionConfig.delete(),
]),
listConfig: const RCKListConfig(showSearchBar: true, pageSize: 20),
),
)
需要完全自定义 UI 外观(如自定义
itemBuilder)时,请参考:会话列表 Builders