Flutter 按按钮颤振时启动动画中的幻灯片
如何重构此幻灯片动画代码以使用onLongPress on my按钮:Flutter 按按钮颤振时启动动画中的幻灯片,flutter,dart,flutter-layout,flutter-dependencies,flutter-android,Flutter,Dart,Flutter Layout,Flutter Dependencies,Flutter Android,如何重构此幻灯片动画代码以使用onLongPress on my按钮: @override void initState() { super.initState(); _controller = AnimationController( duration: const Duration(seconds: 2), vsync: this, )..repeat(reverse: true); _offsetAnimation = Tween<Offset>( begin: O
@override void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
_offsetAnimation = Tween<Offset>(
begin: Offset.zero,
end: const Offset(1.5, 0.0),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.elasticIn,
));
这是我在LongPress上显示的列表:
SlideTransition(
position: _offsetAnimation,
child: Container(
child: ListView.builder(
itemCount: messages.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
onTap: () {},
title: Text(messages[index].emergencyType),
subtitle: Text(messages[index].description),
leading: Icon(Icons.message_outlined),
trailing: Text('Send'),
tileColor: Colors.white,
),
);
})),
),
初始更改时
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
到
并且只需按add
_controller.forward();
结果是动画完全停止了。列表将永久显示在视图中。您希望它在长按时重复吗?不,我只希望它播放一次,但它根本不播放。列表只是放在那里,没有在中设置动画---如中所示,当屏幕加载时,列表也随之加载调用
\u controller.forward()
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
);
_controller.forward();