|
- import 'package:chat/utils/MessageMgr.dart';
- import 'package:flutter/material.dart';
-
- import '../r.dart';
-
- class CoinAnim extends StatefulWidget {
- @required
- final animFinishCallback;
- CoinAnim({Key key, @required this.animFinishCallback});
- @override
- _CoinAnimState createState() => _CoinAnimState();
- }
-
- class _CoinAnimState extends State<CoinAnim>
- with SingleTickerProviderStateMixin {
- Animation<double> _animation;
- AnimationController _controller;
- double begin = 10;
- double end = 2;
-
- @override
- void initState() {
- super.initState();
- // 启动动画controller
- _controller = new AnimationController(
- duration: Duration(milliseconds: 500), vsync: this);
- _controller.addStatusListener((AnimationStatus status) {
- setState(() {});
- if (status == AnimationStatus.completed) {
- widget.animFinishCallback();
- _controller.reverse();
- }
- });
-
- _animation = new Tween<double>(begin: begin, end: end).animate(_controller)
- ..addListener(() {
- setState(() {});
- });
- _controller.forward();
- MessageMgr().on('addCoin', msgAddCoin);
- }
-
- msgAddCoin(data) {
- _controller.forward();
- }
-
- @override
- void dispose() {
- _controller.stop();
- _controller.dispose();
- MessageMgr().off('addCoin', msgAddCoin);
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- return Container(
- margin: EdgeInsets.only(top: _animation.value),
- child: Opacity(
- opacity: 0.6,
- child: Container(
- height: 14,
- margin: EdgeInsets.only(left: 6),
- child: Image.asset(R.assetsImagesCoin))));
- }
- }
|