将曲线应用到现有动画

jus*_*ser 2 dart flutter

项目

大家好,我正在学习如何AnimatedList在 Flutter 中使用。我可以使用以下命令向列表添加和删除元素SizeTransition

代码

Widget _buildItem(
    BuildContext context, int index, Animation<double> animation) {
  return SizeTransition(
    sizeFactor: animation,
    axis: Axis.vertical,
    child: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(
        height: 50,
        color: Colors.orange,
        child: SizedBox(
          child: Center(
            child: Text(displayList[index].toString()),
          ),
        ),
      ),
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

现在,我无法理解如何向此过渡添加自定义曲线。这可能吗?

cre*_*not 5

好问题!

正如文档中的示例提到的,您可以使用CurvedAnimation

CurvedAnimation(
  parent: animation,
  curve: Curves.ease,
  reverseCurve: Curves.easeOut,
),
Run Code Online (Sandbox Code Playgroud)

reverseCurve参数是可选的curve如果没有提供反向曲线,则弯曲动画将仅在两个方向上使用。
应用于您的代码:

return SizeTransition(
  sizeFactor: CurvedAnimation(
    parent: animation,
    curve: Curves.ease,
  ),
  ...
)
Run Code Online (Sandbox Code Playgroud)