flutter - 如何为 Flutter SliverList 中的元素设置动画?

我有一个 SliverList,我将它与 SliverAppBar 一起使用,以便在用户滚动列表时为应用栏设置动画(真的是 slivers 的标准用例,没什么特别的)。

现在我想为 SliverList 中的元素添加动画。例如,添加项目时的水平滑动过渡,或者重新排序列表时元素之间的一种垂直“随机播放”。 AnimatedList 提供了其中一些功能,但 SliverList 不提供。

我对框架的理解是,可能可以将提供给 SliverList 的元素包装在 AnimatedWidget(或一些类似的小部件)中以动画更改.但是我对 Flutter 动画的了解还是有点太新了,所以我寻求帮助。

这是我的部分代码。我想为下面的 GameScoreWidget 实例设置动画。

SliverList(
  delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
    if (index == 0) {
      return ListReorderWidget(viewModel: viewModel);
    }
    else if (!viewModel.isLatestGame(index-1)) {
      return GameScoreWidget(position: index-1, viewModel: viewModel);
    }
    else
      return Dismissible(
        direction: DismissDirection.endToStart,
        child: GameScoreWidget(position: index-1, viewModel: viewModel),
        key: UniqueKey(),
        background: Container(color: Colors.red),
        onDismissed: (direction) {
          onGameDismissed(context);
        },
      );
  },
  childCount: viewModel.games.length+1,
  ),
)

我找不到任何与我的问题相关的答案。我发现这个问题与 Animating changes in a SliverList 相关

但是没有答案...

最佳答案

使用

https://pub.dev/packages/auto_animated

这个包给你 LiveSliverList() 可以用来轻松地为 sliverList 设置动画

https://stackoverflow.com/questions/58757810/

相关文章:

angularjs - 一个指令内的多个方法返回

amazon-web-services - AWS DMS - 错误 - "AWS Account

go - 我可以防止 amqp.Channel 因错误而关闭吗?

c# - 如何检测进程是否移动了鼠标光标而不是用户?

reactjs - React 中的动态标题内容

c# - 显示哪个分数与哪个标签相关的 ML.Net 错误

python - Tensorflow:在 pb 模型中使用 tensorflow.contrib.

python-3.x - matplotlib 错误 : No module named matpl

javascript - 如何仅禁用 chrome 中的 "debugger"关键字,该关键字由循环

python - 如何在 Python 中移动文件?