Flutter:AnimatedList动画曲线

问题描述 投票:0回答:1

如何将曲线(例如Curves.easeIn)添加到AnimatedList的动画中?

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个回答
0
投票

您应该在Tween上调用chain方法。 chain方法采用CurveTween,而CurveTween采用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));
        });
© www.soinside.com 2019 - 2024. All rights reserved.