flutter - 在构建 AnimatedList 时,“insertItem”是如何工作的?
问题描述
特别是,我不明白该insertItem
函数如何知道下面摘录中要添加的项目_animatedList
,因为它的唯一参数是索引位置。
这里发生了什么?
final GlobalKey<AnimatedListState> listKey;
final dynamic removedItemBuilder;
final List<E> _items;
AnimatedListState get _animatedList => listKey.currentState;
void insert(int index, E item) {
_items.insert(index, item);
_animatedList.insertItem(index);
}
以上摘自以下来源:https ://api.flutter.dev/flutter/widgets/AnimatedList-class.html
解决方案
两者都insertItem
只是removeItem
提示在AnimatedList
处设置动画index
。例如在上面的代码中,如果您删除该行
_animatedList.insertItem(index);
您的项目将被添加到_items
列表中,但列表中没有任何动画(没有 UI 更改),即动画对添加到列表中的项目一无所知,它只知道在哪个index
动画
推荐阅读
- java - 在 LinearLayout 底部和我的应用程序底部之间居中图像
- java - 指数函数参数
- css - 位置:固定和变换:translateZ
- python - 如何制作具有分类值的数据透视表?
- material-ui - 如何为同一内容配置多个 Material UI 徽章
- ruby - 具有属性路径一元 * 运算符语法的 Ruby SPARQL 客户端
- php - 使 Doctrine 的 UniqueEntity 约束不区分大小写
- python - 没有 sudo 的 Cron 作业重启
- wordpress - 无法翻译我的 wordpress 网站 - 没有 .pot 文件
- image-processing - 自然语言生成模型中如何控制作者的观点?