Commit e0e89ade4259b1492673268b793465d045cf4bc9
1 parent
2512b58c
feat:选择选项组件动画防抖
Showing
4 changed files
with
19 additions
and
14 deletions
lib/common/widgets/option_widget.dart
| @@ -82,14 +82,15 @@ class _OptionWidgetState extends State<OptionWidget> | @@ -82,14 +82,15 @@ class _OptionWidgetState extends State<OptionWidget> | ||
| 82 | void didUpdateWidget(OptionWidget oldWidget) { | 82 | void didUpdateWidget(OptionWidget oldWidget) { |
| 83 | super.didUpdateWidget(oldWidget); | 83 | super.didUpdateWidget(oldWidget); |
| 84 | Log.d( | 84 | Log.d( |
| 85 | - '$TAG didUpdateWidget widget.isCorrect=${widget.isCorrect} oldWidget.isCorrect=${oldWidget.isCorrect} isAnimation=${_controller.isAnimating} status=${_controller.status}'); | ||
| 86 | - if (widget.isCorrect != oldWidget.isCorrect) { | ||
| 87 | - _controller.reset(); | ||
| 88 | - if (widget.isCorrect == true) { | ||
| 89 | - _controller.forward(); | ||
| 90 | - } else if (widget.isCorrect == false) { | ||
| 91 | - _controller.forward(); | ||
| 92 | - } | 85 | + '$TAG ${identityHashCode(this)} didUpdateWidget widget.isCorrect=${widget.isCorrect} oldWidget.isCorrect=${oldWidget.isCorrect} isAnimation=${_controller.isAnimating} status=${_controller.status}'); |
| 86 | + if (widget.isCorrect == oldWidget.isCorrect && _controller.isAnimating) { | ||
| 87 | + return; | ||
| 88 | + } | ||
| 89 | + _controller.reset(); | ||
| 90 | + if (widget.isCorrect == true) { | ||
| 91 | + _controller.forward(); | ||
| 92 | + } else if (widget.isCorrect == false) { | ||
| 93 | + _controller.forward(); | ||
| 93 | } | 94 | } |
| 94 | } | 95 | } |
| 95 | 96 |
lib/common/widgets/recorder_widget.dart
| @@ -51,7 +51,7 @@ class _RecorderWidgetState extends State<RecorderWidget> | @@ -51,7 +51,7 @@ class _RecorderWidgetState extends State<RecorderWidget> | ||
| 51 | void didUpdateWidget(RecorderWidget oldWidget) { | 51 | void didUpdateWidget(RecorderWidget oldWidget) { |
| 52 | super.didUpdateWidget(oldWidget); | 52 | super.didUpdateWidget(oldWidget); |
| 53 | Log.d( | 53 | Log.d( |
| 54 | - "$TAG didUpdateWidget widget=${widget.isPlaying} oldWidget=${oldWidget.isPlaying} _isPlaying=$_isPlaying"); | 54 | + "$TAG ${identityHashCode(this)} didUpdateWidget widget=${widget.isPlaying} oldWidget=${oldWidget.isPlaying} _isPlaying=$_isPlaying"); |
| 55 | if (widget.isPlaying && !_isPlaying) { | 55 | if (widget.isPlaying && !_isPlaying) { |
| 56 | setState(() { | 56 | setState(() { |
| 57 | _isPlaying = true; | 57 | _isPlaying = true; |
lib/common/widgets/speaker_widget.dart
| @@ -49,6 +49,8 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | @@ -49,6 +49,8 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | ||
| 49 | vsync: this, | 49 | vsync: this, |
| 50 | ); | 50 | ); |
| 51 | 51 | ||
| 52 | + Log.d( | ||
| 53 | + "$TAG ${identityHashCode(this)} initState widget=${widget.isPlaying} _isPlaying=$_isPlaying _controller=${identityHashCode(_controller)}"); | ||
| 52 | if (widget.isPlaying) { | 54 | if (widget.isPlaying) { |
| 53 | _startAnimation(); | 55 | _startAnimation(); |
| 54 | } | 56 | } |
| @@ -58,7 +60,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | @@ -58,7 +60,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | ||
| 58 | void didUpdateWidget(SpeakerWidget oldWidget) { | 60 | void didUpdateWidget(SpeakerWidget oldWidget) { |
| 59 | super.didUpdateWidget(oldWidget); | 61 | super.didUpdateWidget(oldWidget); |
| 60 | Log.d( | 62 | Log.d( |
| 61 | - "$TAG didUpdateWidget widget=${widget.isPlaying} oldWidget=${oldWidget.isPlaying} _isPlaying=$_isPlaying"); | 63 | + "$TAG ${identityHashCode(this)} didUpdateWidget widget=${widget.isPlaying} oldWidget=${oldWidget.isPlaying} _isPlaying=$_isPlaying"); |
| 62 | if (widget.isPlaying && !_isPlaying) { | 64 | if (widget.isPlaying && !_isPlaying) { |
| 63 | setState(() { | 65 | setState(() { |
| 64 | _isPlaying = true; | 66 | _isPlaying = true; |
| @@ -71,7 +73,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | @@ -71,7 +73,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | ||
| 71 | 73 | ||
| 72 | void _startAnimation() { | 74 | void _startAnimation() { |
| 73 | Log.d( | 75 | Log.d( |
| 74 | - "$TAG _startAnimation widget=${widget.isPlaying} _isPlaying=$_isPlaying _controller.isAnimating=${_controller.isAnimating}"); | 76 | + "$TAG ${identityHashCode(this)} _startAnimation widget=${widget.isPlaying} _isPlaying=$_isPlaying isAnimating=${_controller.isAnimating}"); |
| 75 | _timer = Timer.periodic(const Duration(milliseconds: 300), (Timer timer) { | 77 | _timer = Timer.periodic(const Duration(milliseconds: 300), (Timer timer) { |
| 76 | if (mounted) { | 78 | if (mounted) { |
| 77 | setState(() { | 79 | setState(() { |
| @@ -83,7 +85,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | @@ -83,7 +85,7 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | ||
| 83 | 85 | ||
| 84 | void _stopAnimation() { | 86 | void _stopAnimation() { |
| 85 | Log.d( | 87 | Log.d( |
| 86 | - "$TAG _stopAnimation widget=${widget.isPlaying} _isPlaying=$_isPlaying _controller.isAnimating=${_controller.isAnimating}"); | 88 | + "$TAG ${identityHashCode(this)} _stopAnimation widget=${widget.isPlaying} _isPlaying=$_isPlaying isAnimating=${_controller.isAnimating}"); |
| 87 | _timer?.cancel(); | 89 | _timer?.cancel(); |
| 88 | _controller.stop(); | 90 | _controller.stop(); |
| 89 | _controller.reset(); | 91 | _controller.reset(); |
| @@ -98,6 +100,8 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | @@ -98,6 +100,8 @@ class _SpeakerWidgetState extends State<SpeakerWidget> | ||
| 98 | 100 | ||
| 99 | @override | 101 | @override |
| 100 | void dispose() { | 102 | void dispose() { |
| 103 | + Log.d( | ||
| 104 | + "$TAG ${identityHashCode(this)} dispose widget=${widget.isPlaying} _isPlaying=$_isPlaying isAnimating=${_controller.isAnimating}"); | ||
| 101 | _controller.dispose(); | 105 | _controller.dispose(); |
| 102 | _timer?.cancel(); | 106 | _timer?.cancel(); |
| 103 | super.dispose(); | 107 | super.dispose(); |
lib/common/widgets/star_reward_widget.dart
| @@ -60,13 +60,13 @@ class _StarRewardWidgetState extends State<StarRewardWidget> | @@ -60,13 +60,13 @@ class _StarRewardWidgetState extends State<StarRewardWidget> | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void _startAnimation() { | 62 | void _startAnimation() { |
| 63 | - Log.d("$TAG _startAnimation"); | 63 | + Log.d("$TAG ${identityHashCode(this)} _startAnimation"); |
| 64 | setState(() { | 64 | setState(() { |
| 65 | _isVisible = true; | 65 | _isVisible = true; |
| 66 | }); | 66 | }); |
| 67 | 67 | ||
| 68 | _futureComposition.then((composition) { | 68 | _futureComposition.then((composition) { |
| 69 | - Log.d("$TAG _futureComposition.then duration=${composition.duration}"); | 69 | + Log.d("$TAG ${identityHashCode(this)} _futureComposition.then duration=${composition.duration}"); |
| 70 | _controller.duration = composition.duration; | 70 | _controller.duration = composition.duration; |
| 71 | _controller.forward().whenCompleteOrCancel(() { | 71 | _controller.forward().whenCompleteOrCancel(() { |
| 72 | if (mounted) { | 72 | if (mounted) { |