效果图
代码
class MutipleWidget extends StatefulWidget {final double bigRadius;final Color color;final String label;const MutipleWidget({Key key, this.bigRadius, this.color, this.label}): super(key: key);@override_MutipleWidgetState createState() => _MutipleWidgetState();}class _MutipleWidgetState extends State<MutipleWidget>with SingleTickerProviderStateMixin {double bigRadios;AnimationController _animationController;Animation<double> _radioAnimation;Animation<double> _colorAnimation;double _begin = 1;double _end = 0.3;@overridevoid initState() {// TODO: implement initStatesuper.initState();bigRadios = this.widget.bigRadius;_animationController = new AnimationController(vsync: this, duration: Duration(milliseconds: 1000));_colorAnimation = new Tween<double>(begin: _begin, end: _end).animate(CurvedAnimation(parent: _animationController, curve: Curves.easeIn))..addListener(() {setState(() {});});_radioAnimation = new Tween<double>(begin: 0, end: -60).animate(CurvedAnimation(parent: _animationController, curve: Curves.easeIn))..addListener(() {setState(() {});})..addStatusListener((sataus) {if (sataus == AnimationStatus.completed) {Future.delayed(new Duration(milliseconds: 0)).then((value) {_animationController.reverse();});} else if (sataus == AnimationStatus.dismissed) {_animationController.forward();}});_animationController.forward();}@overridevoid deactivate() {// TODO: implement deactivatesuper.deactivate();_animationController.stop();}@overridevoid dispose() {// TODO: implement disposesuper.dispose();_animationController.dispose();}@overrideWidget build(BuildContext context) {return Container(height: bigRadios,width: bigRadios,child: Stack(alignment: Alignment.center,children: <Widget>[//运动的圆Container(height: bigRadios + _radioAnimation.value,width: bigRadios + _radioAnimation.value,decoration:BoxDecoration(shape: BoxShape.circle, color: Colors.white10),child: Container(margin: EdgeInsets.all(40),decoration: BoxDecoration(shape: BoxShape.circle,color: _animationController.status == AnimationStatus.forward? this.widget.color.withOpacity(_colorAnimation.value): this.widget.color),),),//定死不动的的圆Container(height: _getSmall(bigRadios),width: _getSmall(bigRadios),decoration:BoxDecoration(shape: BoxShape.circle, color: Colors.white24),child: Padding(padding: EdgeInsets.all(15),child: Container(decoration: BoxDecoration(shape: BoxShape.circle,color: this.widget.color.withOpacity(0.5)),),),),],),);}double _getSmall(double radios) {return radios - 40;}}
本文分享自微信公众号 - Flutter学习簿(gh_d739155d3b2c)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。


