【发布时间】:2019-05-13 16:58:12
【问题描述】:
我有星星 png 图像,我需要使用 Flutter AnimationController 和 Transformer 旋转星星。我找不到任何图像旋转动画的文档或示例。
知道如何使用 Flutter AnimationController 和 Transform 旋转图像吗?
更新:
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
AnimationController animationController;
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this,
duration: new Duration(milliseconds: 5000),
);
animationController.forward();
animationController.addListener(() {
setState(() {
if (animationController.status == AnimationStatus.completed) {
animationController.repeat();
}
});
});
}
@override
Widget build(BuildContext context) {
return new Container(
alignment: Alignment.center,
color: Colors.white,
child: new AnimatedBuilder(
animation: animationController,
child: new Container(
height: 80.0,
width: 80.0,
child: new Image.asset('images/StarLogo.png'),
),
builder: (BuildContext context, Widget _widget) {
return new Transform.rotate(
angle: animationController.value,
child: _widget,
);
},
),
);
}
}
【问题讨论】:
-
你能通过
animationRotate初始化的代码吗? -
我更新了我的代码。问题是它永远不会旋转 360 度。它旋转了大约 200 圈,然后重新开始,我可以看到它重新绘制了一个间隙。旋转 360 度时遇到问题,当停止时我需要立即重复,以便继续旋转变白停止...
-
更新了答案
标签: flutter dart flutter-layout transform flutter-animation