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

标签 flutter flutter-animation flutter-sliver flutter-animatedlist

我有一个 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 设置动画

关于flutter - 如何为 Flutter SliverList 中的元素设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58757810/

相关文章:

flutter - 如何将自定义动画作为 Flutter 进度/加载指示器?

mobile - 滚动时如何隐藏BottomNavigationBar-Flutter

android-studio - Android Studio - Dart 代码格式问题

flutter - 如何修复此语法错误?不可为 null 的实例字段 'students' 必须初始化

Flutter:如何使用多个流组合

android - 如何在向下滚动后到达 “SliverPersistentHeader” 的第一项之前将 “SliverList” 固定在顶部?

listview - 一些滚动后 flutter ListView KeepAlive

flutter - 将 DraggableScrollableSheet 添加到 Sliver 页面的底部

dart - 自定义滚动 google flutter 中的水平 ListView

java - 在 Android Studio 中调试时证书验证路径错误