Flutter:SlideTransition位移动画,Interval动画延迟

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin{ // 定义 AnimationController late AnimationController _controller; @override void initState() { super.initState(); // 初始化 AnimationController _controller = AnimationController( duration: const Duration(milliseconds: 500), vsync:this, // 让程序和手机的刷新频率统一 ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('标题'), ), body: Center( child: Column( children: [ SlideTransition( // 方块的宽度100,设置x轴y轴位移 0.5:也就是x轴向右移动50,同时向下移动50 position: _controller.drive(Tween(begin: Offset(0, 0),end: Offset(0.5, 0.5))), child: Container( alignment: Alignment.center, width: 100, height: 100, color: Colors.red, ), ), ElevatedButton(onPressed: (){ _controller.repeat(reverse: true); // repeat(reverse: true) 是否循环播放 }, child: const Text('重复')), ElevatedButton(onPressed: (){ _controller.stop(); }, child: const Text('停止')), ElevatedButton(onPressed: (){ _controller.forward(); }, child: const Text('移动')), ElevatedButton(onPressed: (){ _controller.reverse(); }, child: const Text('返回')), ElevatedButton(onPressed: (){ _controller.reset(); }, child: const Text('重置')), ], ), ), ); } }
上一篇:Unity 使用 ExcelDataReader 读取Excel表


下一篇:网络编程套接字概念(UTP和TCP)