import 'package:chat/utils/CustomUI.dart';
import 'package:flutter/material.dart';

class VideoAnim extends StatefulWidget {
  final double begin;
  final int maxTime;
  final double end;
  final double start;
  VideoAnim({
    this.begin,
    this.maxTime = 550,
    this.end,
    this.start = 0,
  });

  @override
  _VideoAnimState createState() => _VideoAnimState();
}

class _VideoAnimState extends State<VideoAnim>
    with SingleTickerProviderStateMixin {
  Animation<double> _animation;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    // 启动动画controller
    _controller = new AnimationController(
        duration: Duration(milliseconds: widget.maxTime), vsync: this);
    _controller.addStatusListener((AnimationStatus status) {
      if (status == AnimationStatus.completed) {
        _controller.reverse();
      } else if (status == AnimationStatus.dismissed) {
        _controller.forward();
      }
    });

    _animation = new Tween<double>(begin: widget.begin, end: widget.end)
        .animate(_controller)
      ..addListener(() {
        setState(() {});
      });

    _controller.forward(from: widget.start);
  }

  @override
  void dispose() {
    _controller.stop();
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CustomUI.buildAudioContaniner(_animation.value);
  }
}
