diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index a3e240d786..d95b4c621f 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -777,8 +777,8 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior> @override Widget build(BuildContext context) { - final ShapeBorder shape = _border!.evaluate(animation!)!; - final double elevation = _elevation!.evaluate(animation!); + final ShapeBorder shape = _border!.evaluate(animation)!; + final double elevation = _elevation!.evaluate(animation); return PhysicalShape( child: _ShapeBorderPaint( child: widget.child, @@ -792,7 +792,7 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior> clipBehavior: widget.clipBehavior, elevation: elevation, color: ElevationOverlay.applyOverlay(context, widget.color, elevation), - shadowColor: _shadowColor!.evaluate(animation!)!, + shadowColor: _shadowColor!.evaluate(animation)!, ); } } diff --git a/packages/flutter/lib/src/material/theme.dart b/packages/flutter/lib/src/material/theme.dart index 2463a62833..5b9bcdc72a 100644 --- a/packages/flutter/lib/src/material/theme.dart +++ b/packages/flutter/lib/src/material/theme.dart @@ -230,7 +230,7 @@ class _AnimatedThemeState extends AnimatedWidgetBaseState { Widget build(BuildContext context) { return Theme( child: widget.child, - data: _data!.evaluate(animation!), + data: _data!.evaluate(animation), ); } diff --git a/packages/flutter/lib/src/widgets/fade_in_image.dart b/packages/flutter/lib/src/widgets/fade_in_image.dart index 19823fc636..b44ac4ec22 100644 --- a/packages/flutter/lib/src/widgets/fade_in_image.dart +++ b/packages/flutter/lib/src/widgets/fade_in_image.dart @@ -464,7 +464,7 @@ class _AnimatedFadeOutFadeInState extends ImplicitlyAnimatedWidgetState<_Animate @override void didUpdateTweens() { - _placeholderOpacityAnimation = animation!.drive(TweenSequence(>[ + _placeholderOpacityAnimation = animation.drive(TweenSequence(>[ TweenSequenceItem( tween: _placeholderOpacity!.chain(CurveTween(curve: widget.fadeOutCurve)), weight: widget.fadeOutDuration.inMilliseconds.toDouble(), @@ -480,7 +480,7 @@ class _AnimatedFadeOutFadeInState extends ImplicitlyAnimatedWidgetState<_Animate } }); - _targetOpacityAnimation = animation!.drive(TweenSequence(>[ + _targetOpacityAnimation = animation.drive(TweenSequence(>[ TweenSequenceItem( tween: ConstantTween(0), weight: widget.fadeOutDuration.inMilliseconds.toDouble(), @@ -493,7 +493,7 @@ class _AnimatedFadeOutFadeInState extends ImplicitlyAnimatedWidgetState<_Animate if (!widget.isTargetLoaded && _isValid(_placeholderOpacity!) && _isValid(_targetOpacity!)) { // Jump (don't fade) back to the placeholder image, so as to be ready // for the full animation when the new target image becomes ready. - controller!.value = controller!.upperBound; + controller.value = controller.upperBound; } } diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 44dadd44c0..c396b27dd5 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -352,22 +352,21 @@ typedef TweenVisitor = Tween? Function(Tween? tween, T t abstract class ImplicitlyAnimatedWidgetState extends State with SingleTickerProviderStateMixin { /// The animation controller driving this widget's implicit animations. @protected - AnimationController? get controller => _controller; - AnimationController? _controller; + AnimationController get controller => _controller; + late final AnimationController _controller = AnimationController( + duration: widget.duration, + debugLabel: kDebugMode ? widget.toStringShort() : null, + vsync: this, + ); /// The animation driving this widget's implicit animations. - Animation? get animation => _animation; - Animation? _animation; + Animation get animation => _animation; + late Animation _animation = _createCurve(); @override void initState() { super.initState(); - _controller = AnimationController( - duration: widget.duration, - debugLabel: kDebugMode ? widget.toStringShort() : null, - vsync: this, - ); - _controller!.addStatusListener((AnimationStatus status) { + _controller.addStatusListener((AnimationStatus status) { switch (status) { case AnimationStatus.completed: if (widget.onEnd != null) @@ -378,7 +377,6 @@ abstract class ImplicitlyAnimatedWidgetState case AnimationStatus.reverse: } }); - _updateCurve(); _constructTweens(); didUpdateTweens(); } @@ -387,27 +385,27 @@ abstract class ImplicitlyAnimatedWidgetState void didUpdateWidget(T oldWidget) { super.didUpdateWidget(oldWidget); if (widget.curve != oldWidget.curve) - _updateCurve(); - _controller!.duration = widget.duration; + _animation = _createCurve(); + _controller.duration = widget.duration; if (_constructTweens()) { forEachTween((Tween? tween, dynamic targetValue, TweenConstructor constructor) { _updateTween(tween, targetValue); return tween; }); - _controller! + _controller ..value = 0.0 ..forward(); didUpdateTweens(); } } - void _updateCurve() { - _animation = CurvedAnimation(parent: _controller!, curve: widget.curve); + CurvedAnimation _createCurve() { + return CurvedAnimation(parent: _controller, curve: widget.curve); } @override void dispose() { - _controller!.dispose(); + _controller.dispose(); super.dispose(); } @@ -419,7 +417,7 @@ abstract class ImplicitlyAnimatedWidgetState if (tween == null) return; tween - ..begin = tween.evaluate(_animation!) + ..begin = tween.evaluate(_animation) ..end = targetValue; } @@ -552,7 +550,7 @@ abstract class AnimatedWidgetBaseState exten @override void initState() { super.initState(); - controller!.addListener(_handleAnimationChanged); + controller.addListener(_handleAnimationChanged); } void _handleAnimationChanged() { @@ -776,7 +774,7 @@ class _AnimatedContainerState extends AnimatedWidgetBaseState @override Widget build(BuildContext context) { - final Animation animation = this.animation!; + final Animation animation = this.animation; return Container( child: widget.child, alignment: _alignment?.evaluate(animation), @@ -907,7 +905,7 @@ class _AnimatedPaddingState extends AnimatedWidgetBaseState { Widget build(BuildContext context) { return Padding( padding: _padding! - .evaluate(animation!) + .evaluate(animation) .clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity), child: widget.child, ); @@ -1058,9 +1056,9 @@ class _AnimatedAlignState extends AnimatedWidgetBaseState { @override Widget build(BuildContext context) { return Align( - alignment: _alignment!.evaluate(animation!)!, - heightFactor: _heightFactorTween?.evaluate(animation!), - widthFactor: _widthFactorTween?.evaluate(animation!), + alignment: _alignment!.evaluate(animation)!, + heightFactor: _heightFactorTween?.evaluate(animation), + widthFactor: _widthFactorTween?.evaluate(animation), child: widget.child, ); } @@ -1255,12 +1253,12 @@ class _AnimatedPositionedState extends AnimatedWidgetBaseState extends AnimatedWidgetBaseSt _currentTween!.begin ??= _currentTween!.end; super.initState(); if (_currentTween!.begin != _currentTween!.end) { - controller!.forward(); + controller.forward(); } } @@ -221,6 +221,6 @@ class _TweenAnimationBuilderState extends AnimatedWidgetBaseSt @override Widget build(BuildContext context) { - return widget.builder(context, _currentTween!.evaluate(animation!), widget.child); + return widget.builder(context, _currentTween!.evaluate(animation), widget.child); } }