【问题标题】:Flutter: AnimatedList animation curveFlutter:AnimatedList动画曲线
【发布时间】:2020-03-20 17:05:41
【问题描述】:

如何向我的 AnimatedList 的动画添加曲线(例如 Curves.easeIn)?

AnimatedList(
  key: _animList,
  initialItemCount: _myList.length,
  itemBuilder: (context, index, animation) {
    return SlideTransition(
      position: animation.drive(Tween(begin: Offset(1, 0), end: Offset(0, 0))), <-- curve?
      child: Container(color: Colors.red, height: 100, width: 100)
    );
  }
)

【问题讨论】:

    标签: flutter animation flutter-animation


    【解决方案1】:

    您应该在 Tween 上调用 chain 方法。 chain 方法采用 CurveTweenCurveTween 采用 curve

    试试这个

        AnimatedList(
            key: _animList,
            initialItemCount: _myList.length,
            itemBuilder: (context, index, animation) {
              return SlideTransition(
                  position: animation.drive(
                      Tween(begin: Offset(1, 0), end: Offset(0, 0))
                          .chain(CurveTween(curve: Curves.bounceIn))),
                  child: Container(color: Colors.red, height: 100, width: 100));
            });
    

    【讨论】:

    • 非常感谢!成功了! :) 有没有办法设置动画的持续时间?
    • 返回前尝试 animation.duration = Duration(seconds: 2);
    • 没用。我得到“没有为类'Animation'定义设置器'duration'”。
    • 噢噢噢噢噢噢
    猜你喜欢
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    相关资源
    最近更新 更多