要让 AnimatedListView 在绑定数据时不执行删除动画直接清空 Item,可以在绑定数据前先将 AnimatedListView 的 controller 设置为 null,然后再绑定新数据。

具体实现步骤如下:

  1. 创建一个 AnimatedListController 实例。
final _listController = AnimatedListController();
  1. 在绑定数据前,将 AnimatedListView 的 controller 设置为 null。
AnimatedListView(
  controller: null,
  ...
)
  1. 绑定新数据时,先调用 controller 的 dispose 方法来清空之前的数据。
_listController.dispose();
  1. 然后再将新的数据绑定到 AnimatedListView 中,并将 controller 设置为 _listController。
AnimatedListView(
  controller: _listController,
  ...
)

这样做的话,就可以在绑定数据时不执行删除动画直接清空 Item 了。

Flutter AnimatedListView 绑定数据清空时如何避免删除动画

原文地址: https://www.cveoy.top/t/topic/lFzL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录