Flutter:实现红包晃动效果
生活随笔
收集整理的這篇文章主要介紹了
Flutter:实现红包晃动效果
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
很多app打開會有紅包懸浮在某個角落,然后為了吸引注意力,會將紅包晃動起來,這個效果非常簡單,代碼如下:
class RedPackageSmall extends StatefulWidget{@overrideState<StatefulWidget> createState() {return _RedPackageSmall();} }class _RedPackageSmall extends State<RedPackageSmall> with SingleTickerProviderStateMixin{Animation _animation;AnimationController _animationController;@overridevoid initState() {super.initState();_animationController = AnimationController(vsync: this,duration: Duration(milliseconds:200),reverseDuration: Duration(milliseconds: 200),);_animation = Tween(begin: -0.03,end: 0.03).animate(_animationController);}@overridevoid dispose() {_animationController.dispose();super.dispose();}@overrideWidget build(BuildContext context) {_animationController.repeat(reverse: true);return RotationTransition(turns: _animation,child: TextButton(onPressed: (){...},child: Image.asset("紅包圖片"),),);}}總結(jié)
以上是生活随笔為你收集整理的Flutter:实现红包晃动效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: getExternalFilesDir到
- 下一篇: flutter web:lottie j