Unverified Commit d7458e3d authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Add asserts for @required parameters (#26449)

Adds asserts on required constructor parameters to a transition widgets.
This improves debuggability for those who aren't developing with live
analysis. e.g. when `turns` is not specified in a RotationTransition
constructor:

  package:flutter/src/widgets/transitions.dart: Failed assertion: line 43 pos 15: 'listenable != null': is not true.

becomes:

  package:flutter/src/widgets/transitions.dart': Failed assertion: line 259 pos 15: 'turns != null': is not true.
parent 9880baa3
...@@ -203,7 +203,8 @@ class ScaleTransition extends AnimatedWidget { ...@@ -203,7 +203,8 @@ class ScaleTransition extends AnimatedWidget {
@required Animation<double> scale, @required Animation<double> scale,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.child, this.child,
}) : super(key: key, listenable: scale); }) : assert(scale != null),
super(key: key, listenable: scale);
/// The animation that controls the scale of the child. /// The animation that controls the scale of the child.
/// ///
...@@ -256,7 +257,8 @@ class RotationTransition extends AnimatedWidget { ...@@ -256,7 +257,8 @@ class RotationTransition extends AnimatedWidget {
@required Animation<double> turns, @required Animation<double> turns,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.child, this.child,
}) : super(key: key, listenable: turns); }) : assert(turns != null),
super(key: key, listenable: turns);
/// The animation that controls the rotation of the child. /// The animation that controls the rotation of the child.
/// ///
...@@ -399,7 +401,8 @@ class FadeTransition extends SingleChildRenderObjectWidget { ...@@ -399,7 +401,8 @@ class FadeTransition extends SingleChildRenderObjectWidget {
@required this.opacity, @required this.opacity,
this.alwaysIncludeSemantics = false, this.alwaysIncludeSemantics = false,
Widget child, Widget child,
}) : super(key: key, child: child); }) : assert(opacity != null),
super(key: key, child: child);
/// The animation that controls the opacity of the child. /// The animation that controls the opacity of the child.
/// ///
...@@ -491,7 +494,8 @@ class PositionedTransition extends AnimatedWidget { ...@@ -491,7 +494,8 @@ class PositionedTransition extends AnimatedWidget {
Key key, Key key,
@required Animation<RelativeRect> rect, @required Animation<RelativeRect> rect,
@required this.child, @required this.child,
}) : super(key: key, listenable: rect); }) : assert(rect != null),
super(key: key, listenable: rect);
/// The animation that controls the child's size and position. /// The animation that controls the child's size and position.
Animation<RelativeRect> get rect => listenable; Animation<RelativeRect> get rect => listenable;
...@@ -543,7 +547,10 @@ class RelativePositionedTransition extends AnimatedWidget { ...@@ -543,7 +547,10 @@ class RelativePositionedTransition extends AnimatedWidget {
@required Animation<Rect> rect, @required Animation<Rect> rect,
@required this.size, @required this.size,
@required this.child, @required this.child,
}) : super(key: key, listenable: rect); }) : assert(rect != null),
assert(size != null),
assert(child != null),
super(key: key, listenable: rect);
/// The animation that controls the child's size and position. /// The animation that controls the child's size and position.
/// ///
...@@ -598,7 +605,9 @@ class DecoratedBoxTransition extends AnimatedWidget { ...@@ -598,7 +605,9 @@ class DecoratedBoxTransition extends AnimatedWidget {
@required this.decoration, @required this.decoration,
this.position = DecorationPosition.background, this.position = DecorationPosition.background,
@required this.child, @required this.child,
}) : super(key: key, listenable: decoration); }) : assert(decoration != null),
assert(child != null),
super(key: key, listenable: decoration);
/// Animation of the decoration to paint. /// Animation of the decoration to paint.
/// ///
...@@ -653,7 +662,9 @@ class AlignTransition extends AnimatedWidget { ...@@ -653,7 +662,9 @@ class AlignTransition extends AnimatedWidget {
@required this.child, @required this.child,
this.widthFactor, this.widthFactor,
this.heightFactor, this.heightFactor,
}) : super(key: key, listenable: alignment); }) : assert(alignment != null),
assert(child != null),
super(key: key, listenable: alignment);
/// The animation that controls the child's alignment. /// The animation that controls the child's alignment.
Animation<AlignmentGeometry> get alignment => listenable; Animation<AlignmentGeometry> get alignment => listenable;
...@@ -698,7 +709,9 @@ class DefaultTextStyleTransition extends AnimatedWidget { ...@@ -698,7 +709,9 @@ class DefaultTextStyleTransition extends AnimatedWidget {
this.softWrap = true, this.softWrap = true,
this.overflow = TextOverflow.clip, this.overflow = TextOverflow.clip,
this.maxLines, this.maxLines,
}) : super(key: key, listenable: style); }) : assert(style != null),
assert(child != null),
super(key: key, listenable: style);
/// The animation that controls the descendants' text style. /// The animation that controls the descendants' text style.
Animation<TextStyle> get style => listenable; Animation<TextStyle> get style => listenable;
...@@ -815,7 +828,8 @@ class AnimatedBuilder extends AnimatedWidget { ...@@ -815,7 +828,8 @@ class AnimatedBuilder extends AnimatedWidget {
@required Listenable animation, @required Listenable animation,
@required this.builder, @required this.builder,
this.child, this.child,
}) : assert(builder != null), }) : assert(animation != null),
assert(builder != null),
super(key: key, listenable: animation); super(key: key, listenable: animation);
/// Called every time the animation changes value. /// Called every time the animation changes value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment