我在 flutter 中使用动画列表加载列表类,在添加或删除项目时,动画有效,但当列表最初加载时,动画不起作用。有没有办法在最初加载列表时为项目设置动画。
class AnimationTest extends StatefulWidget {
@override
_AnimationTestState createState() => _AnimationTestState();
}
class _AnimationTestState extends State<AnimationTest> with SingleTickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedList(
key: _listKey,
initialItemCount: 3,
itemBuilder: (BuildContext context, int index, Animation animation) {
return SlideTransition(
position: animation.drive(Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset.zero)
.chain(CurveTween(curve: Curves.decelerate))),
child: Row(
children: <Widget>[
Expanded( …Run Code Online (Sandbox Code Playgroud)