Hibok
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

83 行
2.0 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:flutter/material.dart';
  3. class FrameAnimation extends StatefulWidget {
  4. final List<int> codeList;
  5. final double size;
  6. final Color color;
  7. final int interval;
  8. final bool isRepeat;
  9. FrameAnimation(
  10. {this.codeList,
  11. this.size,
  12. this.interval = 200,
  13. this.isRepeat = true, this.color,
  14. });
  15. @override
  16. _FrameAnimationState createState() => _FrameAnimationState();
  17. }
  18. class _FrameAnimationState extends State<FrameAnimation>
  19. with SingleTickerProviderStateMixin {
  20. Animation<double> _animation;
  21. AnimationController _controller;
  22. int interval = 1000;
  23. List<Widget> frames = [];
  24. @override
  25. void initState() {
  26. super.initState();
  27. interval = widget.interval;
  28. final int iconCount = widget.codeList.length;
  29. final int maxTime = interval * iconCount;
  30. for (var i = 0; i < iconCount; i++) {
  31. frames.add(Icon(
  32. IconData(widget.codeList[i], fontFamily: Constants.IconFontFamily),
  33. size: widget.size,
  34. color:widget.color));
  35. }
  36. // 启动动画controller
  37. _controller = new AnimationController(
  38. duration: Duration(milliseconds: maxTime), vsync: this);
  39. _controller.addStatusListener((AnimationStatus status) {
  40. if (status == AnimationStatus.completed) {
  41. _controller.forward(from: 0.0); // 完成后重新开始
  42. }
  43. });
  44. _animation = new Tween<double>(begin: 0, end: iconCount.toDouble())
  45. .animate(_controller)
  46. ..addListener(() {
  47. setState(() {});
  48. });
  49. _controller.forward();
  50. }
  51. @override
  52. void dispose() {
  53. _controller.stop();
  54. _controller.dispose();
  55. print('frame animation dipos');
  56. super.dispose();
  57. }
  58. @override
  59. Widget build(BuildContext context) {
  60. int index = _animation.value.floor() % widget.codeList.length;
  61. return IndexedStack(
  62. alignment: Alignment.centerRight,
  63. children: frames,
  64. index: index,
  65. );
  66. }
  67. }