Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.3 KiB

  1. import 'package:flutter/material.dart';
  2. class WhiteOpacityAnim extends StatefulWidget {
  3. final Widget child;
  4. final animFinishCallback;
  5. WhiteOpacityAnim(
  6. {Key key, @required this.child, @required this.animFinishCallback});
  7. @override
  8. _WhiteOpacityAnimState createState() => _WhiteOpacityAnimState();
  9. }
  10. class _WhiteOpacityAnimState extends State<WhiteOpacityAnim>
  11. with SingleTickerProviderStateMixin {
  12. Animation<double> _animation;
  13. AnimationController _controller;
  14. @override
  15. void initState() {
  16. super.initState();
  17. // 启动动画controller
  18. _controller = new AnimationController(
  19. duration: Duration(milliseconds: 1000), vsync: this);
  20. _controller.addStatusListener((AnimationStatus status) {
  21. setState(() {});
  22. if (status == AnimationStatus.completed) {
  23. widget.animFinishCallback();
  24. }
  25. });
  26. _animation = new Tween<double>(begin: 1, end: 0).animate(_controller)
  27. ..addListener(() {
  28. setState(() {});
  29. });
  30. _controller.forward();
  31. }
  32. @override
  33. void dispose() {
  34. _controller.stop();
  35. _controller.dispose();
  36. super.dispose();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return Container(
  41. child: widget.child,
  42. color: Colors.white.withOpacity(_animation.value),
  43. );
  44. }
  45. }