flutter - Flutter 聊天回复消息
问题描述
我正在尝试使用 ListView 构建聊天 UI。我的第一个版本ListView.build
很好用。
我想为“回复消息”选项升级我的聊天视图(类似于whatsapp)。这要求用户能够单击“replyTo”消息并向后滚动到原始消息。ListView.build
不允许向上滚动到屏幕视图之外的消息(因为它甚至没有构建)。
body: Column(
children: [
Expanded(
child: EasyRefresh.custom(
...
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
ChatMessage _currMsg = vm.chat[index]!;
...
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
...
SwipeTo(
onRightSwipe: () {
setState(() {
isReplying = true;
replyMessage = _currMsg;
});
},
child: ShowMessage(
key: Key(_currMsg.id!),
msg: _currMsg,
myMessage: _currMsg.postById == vm.user!.uid,
onTapReply: (id) async {
final ctx = _itemKey.currentContext;
if (ctx != null)
await Scrollable.ensureVisible(ctx);
},
),
),
],
);
},
childCount: vm.chat.length,
),
),
],
),
),
似乎唯一的方法是首先构建所有列表项。
我的问题是,有没有一种方法可以保留已经构建的项目,并且只添加新的传入项目,而不是每次都重建所有项目。
谢谢。
解决方案
推荐阅读
- sql - 不同表的多个案例
- predicate - 饮酒者原则
- python - 如何在 override.AbsOverride maya 2018 或 2019 中设置设置属性('primaryVisibility')
- tensorflow - Tensorflow 2.0 如何在 __call__ 函数中将 tf.Variable 作为权重处理?
- flutter - 在颤振中使用带有 isComplex 和 willChange 的 CustomPainter
- filemaker - 如何获取 FIlemaker 文件| 编辑| 后视图栏
- javascript - 如何修复我的 POST 函数代码可以与服务器通信?
- java - 如何从网页获取mysql插入百分比?
- excel - 如何使用 VLOOKUP 将多值单元格拆分为单独的行?
- javascript - 根据所选值添加多个字段