diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 5a19b5c57c..32b6b36ca5 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -359,8 +359,7 @@ abstract class ImplicitlyAnimatedWidgetState with SingleTickerProviderStateMixin { /// The animation controller driving this widget's implicit animations. @protected - AnimationController get controller => _controller; - late final AnimationController _controller = AnimationController( + late final AnimationController controller = AnimationController( duration: widget.duration, debugLabel: kDebugMode ? widget.toStringShort() : null, vsync: this, @@ -374,7 +373,7 @@ abstract class ImplicitlyAnimatedWidgetState @override void initState() { super.initState(); - _controller.addStatusListener((AnimationStatus status) { + controller.addStatusListener((AnimationStatus status) { if (status.isCompleted) { widget.onEnd?.call(); } @@ -391,48 +390,34 @@ abstract class ImplicitlyAnimatedWidgetState _animation.dispose(); _animation = _createCurve(); } - _controller.duration = widget.duration; + controller.duration = widget.duration; if (_constructTweens()) { forEachTween(( Tween? tween, dynamic targetValue, TweenConstructor constructor, ) { - _updateTween(tween, targetValue); - return tween; + return tween + ?..begin = tween.evaluate(_animation) + ..end = targetValue; }); - _controller - ..value = 0.0 - ..forward(); + controller.forward(from: 0.0); didUpdateTweens(); } } CurvedAnimation _createCurve() { - return CurvedAnimation(parent: _controller, curve: widget.curve); + return CurvedAnimation(parent: controller, curve: widget.curve); } @protected @override void dispose() { _animation.dispose(); - _controller.dispose(); + controller.dispose(); super.dispose(); } - bool _shouldAnimateTween(Tween tween, dynamic targetValue) { - return targetValue != (tween.end ?? tween.begin); - } - - void _updateTween(Tween? tween, dynamic targetValue) { - if (tween == null) { - return; - } - tween - ..begin = tween.evaluate(_animation) - ..end = targetValue; - } - bool _constructTweens() { bool shouldStartAnimation = false; forEachTween(( @@ -442,7 +427,7 @@ abstract class ImplicitlyAnimatedWidgetState ) { if (targetValue != null) { tween ??= constructor(targetValue); - if (_shouldAnimateTween(tween, targetValue)) { + if (targetValue != (tween.end ?? tween.begin)) { shouldStartAnimation = true; } else { tween.end ??= tween.begin;