基本上我有一个小部件和一个浮动操作按钮,我想让该小部件在按下按钮时移动,我设法将其传送到随机位置,但我希望它具有动画效果。
我希望我的小部件在按下按钮时能够从当前位置移动到新位置。
randomNumber() 函数也是一个在最小值和最大值之间选择随机数的函数。 随机数(最小值,最大值);
class _homePageState extends State<homePage> with SingleTickerProviderStateMixin{
late final AnimationController _animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 1),
)..forward();
@override
void initState() {
super.initState();
}
double beginX = randomNumber(-1, 1);
double beginY = randomNumber(-1, 1);
double endX = randomNumber(-1, 1);
double endY = randomNumber(-1, 1);
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
late final Animation<Offset> _animation = Tween<Offset>(
begin: Offset(beginX, beginY),
end: Offset(endX, endY),
).animate(_animationController);
return Scaffold(
body: Center(
child: SlideTransition( …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个带有容器的 SlideTransition,它会永远重复,但我希望每次重复后有一个延迟。所以它会是这样的:
这是我的代码
late final AnimationController _animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 1)
)..repeat(reverse: true); // Here there should be the 500 millisecond delay
late final Animation<Offset> _animation = Tween<Offset>(
begin: Offset.zero,
end: Offset(0, 1),
).animate(_animationController);
Run Code Online (Sandbox Code Playgroud)
return Scaffold(
body: Center(
child: SlideTransition(
position: _animation,
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
),
);
Run Code Online (Sandbox Code Playgroud)