@@ -352,22 +352,21 @@ typedef TweenVisitor<T extends Object> = Tween<T>? Function(Tween<T>? tween, T t
352352abstract class ImplicitlyAnimatedWidgetState <T extends ImplicitlyAnimatedWidget > extends State <T > with SingleTickerProviderStateMixin <T > {
353353 /// The animation controller driving this widget's implicit animations.
354354 @protected
355- AnimationController ? get controller => _controller;
356- AnimationController ? _controller;
355+ AnimationController get controller => _controller;
356+ late final AnimationController _controller = AnimationController (
357+ duration: widget.duration,
358+ debugLabel: kDebugMode ? widget.toStringShort () : null ,
359+ vsync: this ,
360+ );
357361
358362 /// The animation driving this widget's implicit animations.
359- Animation <double >? get animation => _animation;
360- Animation <double >? _animation;
363+ Animation <double > get animation => _animation;
364+ late Animation <double > _animation = _createCurve () ;
361365
362366 @override
363367 void initState () {
364368 super .initState ();
365- _controller = AnimationController (
366- duration: widget.duration,
367- debugLabel: kDebugMode ? widget.toStringShort () : null ,
368- vsync: this ,
369- );
370- _controller! .addStatusListener ((AnimationStatus status) {
369+ _controller.addStatusListener ((AnimationStatus status) {
371370 switch (status) {
372371 case AnimationStatus .completed:
373372 if (widget.onEnd != null )
@@ -378,7 +377,6 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
378377 case AnimationStatus .reverse:
379378 }
380379 });
381- _updateCurve ();
382380 _constructTweens ();
383381 didUpdateTweens ();
384382 }
@@ -387,27 +385,27 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
387385 void didUpdateWidget (T oldWidget) {
388386 super .didUpdateWidget (oldWidget);
389387 if (widget.curve != oldWidget.curve)
390- _updateCurve ();
391- _controller! .duration = widget.duration;
388+ _animation = _createCurve ();
389+ _controller.duration = widget.duration;
392390 if (_constructTweens ()) {
393391 forEachTween ((Tween <dynamic >? tween, dynamic targetValue, TweenConstructor <dynamic > constructor) {
394392 _updateTween (tween, targetValue);
395393 return tween;
396394 });
397- _controller!
395+ _controller
398396 ..value = 0.0
399397 ..forward ();
400398 didUpdateTweens ();
401399 }
402400 }
403401
404- void _updateCurve () {
405- _animation = CurvedAnimation (parent: _controller! , curve: widget.curve);
402+ CurvedAnimation _createCurve () {
403+ return CurvedAnimation (parent: _controller, curve: widget.curve);
406404 }
407405
408406 @override
409407 void dispose () {
410- _controller! .dispose ();
408+ _controller.dispose ();
411409 super .dispose ();
412410 }
413411
@@ -419,7 +417,7 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
419417 if (tween == null )
420418 return ;
421419 tween
422- ..begin = tween.evaluate (_animation! )
420+ ..begin = tween.evaluate (_animation)
423421 ..end = targetValue;
424422 }
425423
@@ -552,7 +550,7 @@ abstract class AnimatedWidgetBaseState<T extends ImplicitlyAnimatedWidget> exten
552550 @override
553551 void initState () {
554552 super .initState ();
555- controller! .addListener (_handleAnimationChanged);
553+ controller.addListener (_handleAnimationChanged);
556554 }
557555
558556 void _handleAnimationChanged () {
@@ -776,7 +774,7 @@ class _AnimatedContainerState extends AnimatedWidgetBaseState<AnimatedContainer>
776774
777775 @override
778776 Widget build (BuildContext context) {
779- final Animation <double > animation = this .animation! ;
777+ final Animation <double > animation = this .animation;
780778 return Container (
781779 child: widget.child,
782780 alignment: _alignment? .evaluate (animation),
@@ -907,7 +905,7 @@ class _AnimatedPaddingState extends AnimatedWidgetBaseState<AnimatedPadding> {
907905 Widget build (BuildContext context) {
908906 return Padding (
909907 padding: _padding!
910- .evaluate (animation! )
908+ .evaluate (animation)
911909 .clamp (EdgeInsets .zero, EdgeInsetsGeometry .infinity),
912910 child: widget.child,
913911 );
@@ -1058,9 +1056,9 @@ class _AnimatedAlignState extends AnimatedWidgetBaseState<AnimatedAlign> {
10581056 @override
10591057 Widget build (BuildContext context) {
10601058 return Align (
1061- alignment: _alignment! .evaluate (animation! )! ,
1062- heightFactor: _heightFactorTween? .evaluate (animation! ),
1063- widthFactor: _widthFactorTween? .evaluate (animation! ),
1059+ alignment: _alignment! .evaluate (animation)! ,
1060+ heightFactor: _heightFactorTween? .evaluate (animation),
1061+ widthFactor: _widthFactorTween? .evaluate (animation),
10641062 child: widget.child,
10651063 );
10661064 }
@@ -1255,12 +1253,12 @@ class _AnimatedPositionedState extends AnimatedWidgetBaseState<AnimatedPositione
12551253 Widget build (BuildContext context) {
12561254 return Positioned (
12571255 child: widget.child,
1258- left: _left? .evaluate (animation! ),
1259- top: _top? .evaluate (animation! ),
1260- right: _right? .evaluate (animation! ),
1261- bottom: _bottom? .evaluate (animation! ),
1262- width: _width? .evaluate (animation! ),
1263- height: _height? .evaluate (animation! ),
1256+ left: _left? .evaluate (animation),
1257+ top: _top? .evaluate (animation),
1258+ right: _right? .evaluate (animation),
1259+ bottom: _bottom? .evaluate (animation),
1260+ width: _width? .evaluate (animation),
1261+ height: _height? .evaluate (animation),
12641262 );
12651263 }
12661264
@@ -1392,12 +1390,12 @@ class _AnimatedPositionedDirectionalState extends AnimatedWidgetBaseState<Animat
13921390 return Positioned .directional (
13931391 textDirection: Directionality .of (context),
13941392 child: widget.child,
1395- start: _start? .evaluate (animation! ),
1396- top: _top? .evaluate (animation! ),
1397- end: _end? .evaluate (animation! ),
1398- bottom: _bottom? .evaluate (animation! ),
1399- width: _width? .evaluate (animation! ),
1400- height: _height? .evaluate (animation! ),
1393+ start: _start? .evaluate (animation),
1394+ top: _top? .evaluate (animation),
1395+ end: _end? .evaluate (animation),
1396+ bottom: _bottom? .evaluate (animation),
1397+ width: _width? .evaluate (animation),
1398+ height: _height? .evaluate (animation),
14011399 );
14021400 }
14031401
@@ -1529,7 +1527,7 @@ class _AnimatedOpacityState extends ImplicitlyAnimatedWidgetState<AnimatedOpacit
15291527
15301528 @override
15311529 void didUpdateTweens () {
1532- _opacityAnimation = animation! .drive (_opacity! );
1530+ _opacityAnimation = animation.drive (_opacity! );
15331531 }
15341532
15351533 @override
@@ -1662,7 +1660,7 @@ class _SliverAnimatedOpacityState extends ImplicitlyAnimatedWidgetState<SliverAn
16621660
16631661 @override
16641662 void didUpdateTweens () {
1665- _opacityAnimation = animation! .drive (_opacity! );
1663+ _opacityAnimation = animation.drive (_opacity! );
16661664 }
16671665
16681666 @override
@@ -1792,7 +1790,7 @@ class _AnimatedDefaultTextStyleState extends AnimatedWidgetBaseState<AnimatedDef
17921790 @override
17931791 Widget build (BuildContext context) {
17941792 return DefaultTextStyle (
1795- style: _style! .evaluate (animation! ),
1793+ style: _style! .evaluate (animation),
17961794 textAlign: widget.textAlign,
17971795 softWrap: widget.softWrap,
17981796 overflow: widget.overflow,
@@ -1925,11 +1923,11 @@ class _AnimatedPhysicalModelState extends AnimatedWidgetBaseState<AnimatedPhysic
19251923 child: widget.child,
19261924 shape: widget.shape,
19271925 clipBehavior: widget.clipBehavior,
1928- borderRadius: _borderRadius! .evaluate (animation! ),
1929- elevation: _elevation! .evaluate (animation! ),
1930- color: widget.animateColor ? _color! .evaluate (animation! )! : widget.color,
1926+ borderRadius: _borderRadius! .evaluate (animation),
1927+ elevation: _elevation! .evaluate (animation),
1928+ color: widget.animateColor ? _color! .evaluate (animation)! : widget.color,
19311929 shadowColor: widget.animateShadowColor
1932- ? _shadowColor! .evaluate (animation! )!
1930+ ? _shadowColor! .evaluate (animation)!
19331931 : widget.shadowColor,
19341932 );
19351933 }
0 commit comments