大家好,我正在学习如何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)
现在,我无法理解如何向此过渡添加自定义曲线。这可能吗?
好问题!
正如文档中的示例提到的,您可以使用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)
| 归档时间: |
|
| 查看次数: |
482 次 |
| 最近记录: |