【问题标题】:How can I add animation on flutter for dynamic list of items?如何为动态项目列表添加颤动动画?
【发布时间】:2020-05-24 03:17:16
【问题描述】:

我正在为一款游戏构建一个应用程序,您可以在其中跟踪装甲的升级等级。每个级别都有一些升级所需的材料。例如:

Level 1 - 10 of Materials A
Level 2 - 5 of Materials B
Level 3 - 10 of Materials C

我有一个页面,其中有一个星级小部件,当用户更改时,它会更新我的盔甲的等级属性。通过使用提供程序,我的材料列表会更新为仅显示剩余的材料。 所以如果我的盔甲在 1 级,它会显示:

Level 2 - 5 Materials B
Level 3 - 10 Materials C

当我的盔甲在 2 级时,它会显示:

Level 3 - 10 Materials C

我想做的是在该材料离开屏幕时添加动画,而不是仅仅隐藏它。

这是我必须显示包含信息的行列表的设置

        Column(
            children: armor.listOfUpgradeMaterials.map((material) {
          return Container(
            child: Column(children: [
                MaterialByLevelRow(material),
              Divider(
                color: Theme.of(context).accentColor.withOpacity(0.5),
                height: 0,
              ),
            ]),
          );
        }).toList())

现在在我的 MaterialByLevelRow 小部件中,我有一个带有

的 AnimatedContainer
 height: shouldDisplayRow ? 40 : 0,

这是最好的选择吗?这样,屏幕上会出现几行,但高度为零,这不是一个坏习惯吗?

如果我想添加一个改变高度的滑入式动画,可以吗?

【问题讨论】:

    标签: flutter flutter-animation


    【解决方案1】:

    尝试使用 AnimatedList() 小部件。

    更多帮助请参考这篇博文:https://medium.com/flutter-community/updating-data-in-an-animatedlist-in-flutter-9dbfb136e515

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 2012-07-12
      • 1970-01-01
      相关资源
      最近更新 更多