diff --git a/packages/flutter/lib/src/widgets/animated_cross_fade.dart b/packages/flutter/lib/src/widgets/animated_cross_fade.dart index 1214a0fcc2..8561ffb5dd 100644 --- a/packages/flutter/lib/src/widgets/animated_cross_fade.dart +++ b/packages/flutter/lib/src/widgets/animated_cross_fade.dart @@ -248,7 +248,7 @@ class AnimatedCrossFade extends StatefulWidget { } class _AnimatedCrossFadeState extends State with TickerProviderStateMixin { - AnimationController? _controller; + late AnimationController _controller; late Animation _firstAnimation; late Animation _secondAnimation; @@ -261,10 +261,10 @@ class _AnimatedCrossFadeState extends State with TickerProvid vsync: this, ); if (widget.crossFadeState == CrossFadeState.showSecond) - _controller!.value = 1.0; + _controller.value = 1.0; _firstAnimation = _initAnimation(widget.firstCurve, true); _secondAnimation = _initAnimation(widget.secondCurve, false); - _controller!.addStatusListener((AnimationStatus status) { + _controller.addStatusListener((AnimationStatus status) { setState(() { // Trigger a rebuild because it depends on _isTransitioning, which // changes its value together with animation status. @@ -273,7 +273,7 @@ class _AnimatedCrossFadeState extends State with TickerProvid } Animation _initAnimation(Curve curve, bool inverted) { - Animation result = _controller!.drive(CurveTween(curve: curve)); + Animation result = _controller.drive(CurveTween(curve: curve)); if (inverted) result = result.drive(Tween(begin: 1.0, end: 0.0)); return result; @@ -281,7 +281,7 @@ class _AnimatedCrossFadeState extends State with TickerProvid @override void dispose() { - _controller!.dispose(); + _controller.dispose(); super.dispose(); } @@ -289,9 +289,9 @@ class _AnimatedCrossFadeState extends State with TickerProvid void didUpdateWidget(AnimatedCrossFade oldWidget) { super.didUpdateWidget(oldWidget); if (widget.duration != oldWidget.duration) - _controller!.duration = widget.duration; + _controller.duration = widget.duration; if (widget.reverseDuration != oldWidget.reverseDuration) - _controller!.reverseDuration = widget.reverseDuration; + _controller.reverseDuration = widget.reverseDuration; if (widget.firstCurve != oldWidget.firstCurve) _firstAnimation = _initAnimation(widget.firstCurve, true); if (widget.secondCurve != oldWidget.secondCurve) @@ -299,24 +299,24 @@ class _AnimatedCrossFadeState extends State with TickerProvid if (widget.crossFadeState != oldWidget.crossFadeState) { switch (widget.crossFadeState) { case CrossFadeState.showFirst: - _controller!.reverse(); + _controller.reverse(); break; case CrossFadeState.showSecond: - _controller!.forward(); + _controller.forward(); break; } } } /// Whether we're in the middle of cross-fading this frame. - bool get _isTransitioning => _controller!.status == AnimationStatus.forward || _controller!.status == AnimationStatus.reverse; + bool get _isTransitioning => _controller.status == AnimationStatus.forward || _controller.status == AnimationStatus.reverse; @override Widget build(BuildContext context) { const Key kFirstChildKey = ValueKey(CrossFadeState.showFirst); const Key kSecondChildKey = ValueKey(CrossFadeState.showSecond); - final bool transitioningForwards = _controller!.status == AnimationStatus.completed || - _controller!.status == AnimationStatus.forward; + final bool transitioningForwards = _controller.status == AnimationStatus.completed || + _controller.status == AnimationStatus.forward; final Key topKey; Widget topChild; final Animation topAnimation;