From c63be2af8bb79e70e93750ae4ade89ff35e29fa7 Mon Sep 17 00:00:00 2001 From: Alexandre Ardhuin Date: Mon, 5 Jun 2017 09:33:38 +0200 Subject: [PATCH] apply prefer_asserts_in_initializer_list lint (#10483) --- .../src/animation/animation_controller.dart | 30 +++++++++--------- .../flutter/lib/src/animation/animations.dart | 20 +++++------- packages/flutter/lib/src/animation/tween.dart | 5 ++- .../lib/src/cupertino/bottom_tab_bar.dart | 11 +++---- packages/flutter/lib/src/cupertino/page.dart | 31 +++++++++---------- .../flutter/lib/src/cupertino/slider.dart | 4 +-- .../flutter/lib/src/cupertino/switch.dart | 16 +++++----- .../lib/src/gestures/drag_details.dart | 30 +++++++----------- .../flutter/lib/src/gestures/lsq_solver.dart | 7 ++--- .../flutter/lib/src/gestures/multidrag.dart | 14 ++++----- packages/flutter/lib/src/gestures/scale.dart | 19 ++++++------ packages/flutter/lib/src/gestures/tap.dart | 10 +++--- 12 files changed, 88 insertions(+), 109 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index 9619ed4faf9..6e04b18326d 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -115,12 +115,11 @@ class AnimationController extends Animation this.lowerBound: 0.0, this.upperBound: 1.0, @required TickerProvider vsync, - }) { - assert(lowerBound != null); - assert(upperBound != null); - assert(upperBound >= lowerBound); - assert(vsync != null); - _direction = _AnimationDirection.forward; + }) : assert(lowerBound != null), + assert(upperBound != null), + assert(upperBound >= lowerBound), + assert(vsync != null), + _direction = _AnimationDirection.forward { _ticker = vsync.createTicker(_tick); _internalSetValue(value ?? lowerBound); } @@ -146,11 +145,11 @@ class AnimationController extends Animation this.duration, this.debugLabel, @required TickerProvider vsync, - }) : lowerBound = double.NEGATIVE_INFINITY, - upperBound = double.INFINITY { - assert(value != null); - assert(vsync != null); - _direction = _AnimationDirection.forward; + }) : assert(value != null), + assert(vsync != null), + lowerBound = double.NEGATIVE_INFINITY, + upperBound = double.INFINITY, + _direction = _AnimationDirection.forward { _ticker = vsync.createTicker(_tick); _internalSetValue(value); } @@ -496,11 +495,10 @@ class AnimationController extends Animation class _InterpolationSimulation extends Simulation { _InterpolationSimulation(this._begin, this._end, Duration duration, this._curve) - : _durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND { - assert(_durationInSeconds > 0.0); - assert(_begin != null); - assert(_end != null); - } + : assert(_begin != null), + assert(_end != null), + assert(duration != null && duration.inMicroseconds > 0), + _durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND; final double _durationInSeconds; final double _begin; diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index 9401108c920..b763b792cdc 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -247,9 +247,8 @@ class ReverseAnimation extends Animation /// Creates a reverse animation. /// /// The parent argument must not be null. - ReverseAnimation(this.parent) { - assert(parent != null); - } + ReverseAnimation(this.parent) + : assert(parent != null); /// The animation whose value and direction this animation is reversing. final Animation parent; @@ -331,9 +330,8 @@ class CurvedAnimation extends Animation with AnimationWithParentMixin /// /// The current train argument must not be null but the next train argument /// can be null. - TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) { - assert(_currentTrain != null); + TrainHoppingAnimation(this._currentTrain, this._nextTrain, { this.onSwitchedTrain }) + : assert(_currentTrain != null) { if (_nextTrain != null) { if (_currentTrain.value > _nextTrain.value) { _mode = _TrainHoppingMode.maximize; @@ -552,10 +550,8 @@ abstract class CompoundAnimation extends Animation CompoundAnimation({ @required this.first, @required this.next, - }) { - assert(first != null); - assert(next != null); - } + }) : assert(first != null), + assert(next != null); /// The first sub-animation. Its status takes precedence if neither are /// animating. diff --git a/packages/flutter/lib/src/animation/tween.dart b/packages/flutter/lib/src/animation/tween.dart index e993a003db2..1db4175c6ac 100644 --- a/packages/flutter/lib/src/animation/tween.dart +++ b/packages/flutter/lib/src/animation/tween.dart @@ -291,9 +291,8 @@ class CurveTween extends Animatable { /// Creates a curve tween. /// /// The [curve] argument must not be null. - CurveTween({ @required this.curve }) { - assert(curve != null); - } + CurveTween({ @required this.curve }) + : assert(curve != null); /// The curve to use when transforming the value of the animation. Curve curve; diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index cd4cc55f987..59472f35320 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -41,12 +41,11 @@ class CupertinoTabBar extends StatelessWidget { this.activeColor: CupertinoColors.activeBlue, this.inactiveColor: CupertinoColors.inactiveGray, this.iconSize: 24.0, - }) : super(key: key) { - assert(items != null); - assert(items.length >= 2); - assert(0 <= currentIndex && currentIndex < items.length); - assert(iconSize != null); - } + }) : assert(items != null), + assert(items.length >= 2), + assert(0 <= currentIndex && currentIndex < items.length), + assert(iconSize != null), + super(key: key); /// The interactive items laid out within the bottom navigation bar. final List items; diff --git a/packages/flutter/lib/src/cupertino/page.dart b/packages/flutter/lib/src/cupertino/page.dart index 59c27d347a6..a25ef52827c 100644 --- a/packages/flutter/lib/src/cupertino/page.dart +++ b/packages/flutter/lib/src/cupertino/page.dart @@ -25,7 +25,7 @@ final FractionalOffsetTween _kBottomUpTween = new FractionalOffsetTween( end: FractionalOffset.topLeft, ); -// Custom decoration from no shadow to page shadow mimicking iOS page +// Custom decoration from no shadow to page shadow mimicking iOS page // transitions using gradients. final DecorationTween _kGradientShadowTween = new DecorationTween( begin: _CupertinoEdgeShadowDecoration.none, // No decoration initially. @@ -36,27 +36,27 @@ final DecorationTween _kGradientShadowTween = new DecorationTween( end: FractionalOffset.topRight, // Eyeballed gradient used to mimic a drop shadow on the left side only. colors: const [ - const Color(0x00000000), + const Color(0x00000000), const Color(0x04000000), const Color(0x12000000), const Color(0x38000000) ], stops: const [0.0, 0.3, 0.6, 1.0], - ), + ), ), ); -/// A custom [Decoration] used to paint an extra shadow on the left edge of the -/// box it's decorating. It's like a [BoxDecoration] with only a gradient except +/// A custom [Decoration] used to paint an extra shadow on the left edge of the +/// box it's decorating. It's like a [BoxDecoration] with only a gradient except /// it paints to the left of the box instead of behind the box. class _CupertinoEdgeShadowDecoration extends Decoration { const _CupertinoEdgeShadowDecoration({ this.edgeGradient }); /// A Decoration with no decorating properties. - static const _CupertinoEdgeShadowDecoration none = + static const _CupertinoEdgeShadowDecoration none = const _CupertinoEdgeShadowDecoration(); - /// A gradient to draw to the left of the box being decorated. + /// A gradient to draw to the left of the box being decorated. /// FractionalOffsets are relative to the original box translated one box /// width to the left. final LinearGradient edgeGradient; @@ -65,8 +65,8 @@ class _CupertinoEdgeShadowDecoration extends Decoration { /// /// See also [Decoration.lerp]. static _CupertinoEdgeShadowDecoration lerp( - _CupertinoEdgeShadowDecoration a, - _CupertinoEdgeShadowDecoration b, + _CupertinoEdgeShadowDecoration a, + _CupertinoEdgeShadowDecoration b, double t ) { if (a == null && b == null) @@ -89,7 +89,7 @@ class _CupertinoEdgeShadowDecoration extends Decoration { return _CupertinoEdgeShadowDecoration.lerp(this, null, t); return _CupertinoEdgeShadowDecoration.lerp(this, b, t); } - + @override _CupertinoEdgeShadowPainter createBoxPainter([VoidCallback onChanged]) { return new _CupertinoEdgeShadowPainter(this, onChanged); @@ -114,7 +114,7 @@ class _CupertinoEdgeShadowDecoration extends Decoration { /// A [BoxPainter] used to draw the page transition shadow using gradients. class _CupertinoEdgeShadowPainter extends BoxPainter { _CupertinoEdgeShadowPainter( - @required this._decoration, + @required this._decoration, VoidCallback onChange ) : assert(_decoration != null), super(onChange); @@ -126,9 +126,9 @@ class _CupertinoEdgeShadowPainter extends BoxPainter { final LinearGradient gradient = _decoration.edgeGradient; if (gradient == null) return; - // The drawable space for the gradient is a rect with the same size as + // The drawable space for the gradient is a rect with the same size as // its parent box one box width to the left of the box. - final Rect rect = + final Rect rect = (offset & configuration.size).translate(-configuration.size.width, 0.0); final Paint paint = new Paint() ..shader = gradient.createShader(rect); @@ -249,9 +249,8 @@ class CupertinoBackGestureController extends NavigationGestureController { CupertinoBackGestureController({ @required NavigatorState navigator, @required this.controller, - }) : super(navigator) { - assert(controller != null); - } + }) : assert(controller != null), + super(navigator); /// The animation controller that the route uses to drive its transition /// animation. diff --git a/packages/flutter/lib/src/cupertino/slider.dart b/packages/flutter/lib/src/cupertino/slider.dart index e23ea3ab330..8ed550ad23b 100644 --- a/packages/flutter/lib/src/cupertino/slider.dart +++ b/packages/flutter/lib/src/cupertino/slider.dart @@ -192,11 +192,11 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements SemanticsAc Color activeColor, this.onChanged, TickerProvider vsync, - }) : _value = value, + }) : assert(value != null && value >= 0.0 && value <= 1.0), + _value = value, _divisions = divisions, _activeColor = activeColor, super(additionalConstraints: const BoxConstraints.tightFor(width: _kSliderWidth, height: _kSliderHeight)) { - assert(value != null && value >= 0.0 && value <= 1.0); _drag = new HorizontalDragGestureRecognizer() ..onStart = _handleDragStart ..onUpdate = _handleDragUpdate diff --git a/packages/flutter/lib/src/cupertino/switch.dart b/packages/flutter/lib/src/cupertino/switch.dart index 28d1da9339f..8c91132ea8a 100644 --- a/packages/flutter/lib/src/cupertino/switch.dart +++ b/packages/flutter/lib/src/cupertino/switch.dart @@ -141,14 +141,14 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox implements SemanticsAc @required Color activeColor, ValueChanged onChanged, @required TickerProvider vsync, - }) : _value = value, - _activeColor = activeColor, - _onChanged = onChanged, - _vsync = vsync, - super(additionalConstraints: const BoxConstraints.tightFor(width: _kSwitchWidth, height: _kSwitchHeight)) { - assert(value != null); - assert(activeColor != null); - assert(vsync != null); + }) : assert(value != null), + assert(activeColor != null), + assert(vsync != null), + _value = value, + _activeColor = activeColor, + _onChanged = onChanged, + _vsync = vsync, + super(additionalConstraints: const BoxConstraints.tightFor(width: _kSwitchWidth, height: _kSwitchHeight)) { _tap = new TapGestureRecognizer() ..onTapDown = _handleTapDown ..onTap = _handleTap diff --git a/packages/flutter/lib/src/gestures/drag_details.dart b/packages/flutter/lib/src/gestures/drag_details.dart index 9cdfdb0131b..7cd2ef2ce36 100644 --- a/packages/flutter/lib/src/gestures/drag_details.dart +++ b/packages/flutter/lib/src/gestures/drag_details.dart @@ -20,9 +20,8 @@ class DragDownDetails { /// Creates details for a [GestureDragDownCallback]. /// /// The [globalPosition] argument must not be null. - DragDownDetails({ this.globalPosition: Offset.zero }) { - assert(globalPosition != null); - } + DragDownDetails({ this.globalPosition: Offset.zero }) + : assert(globalPosition != null); /// The global position at which the pointer contacted the screen. /// @@ -53,9 +52,8 @@ class DragStartDetails { /// Creates details for a [GestureDragStartCallback]. /// /// The [globalPosition] argument must not be null. - DragStartDetails({ this.globalPosition: Offset.zero }) { - assert(globalPosition != null); - } + DragStartDetails({ this.globalPosition: Offset.zero }) + : assert(globalPosition != null); /// The global position at which the pointer contacted the screen. /// @@ -99,12 +97,10 @@ class DragUpdateDetails { this.delta: Offset.zero, this.primaryDelta, @required this.globalPosition - }) { - assert(delta != null); - assert(primaryDelta == null - || (primaryDelta == delta.dx && delta.dy == 0.0) - || (primaryDelta == delta.dy && delta.dx == 0.0)); - } + }) : assert(delta != null), + assert(primaryDelta == null + || (primaryDelta == delta.dx && delta.dy == 0.0) + || (primaryDelta == delta.dy && delta.dx == 0.0)); /// The amount the pointer has moved since the previous update. /// @@ -158,12 +154,10 @@ class DragEndDetails { DragEndDetails({ this.velocity: Velocity.zero, this.primaryVelocity, - }) { - assert(velocity != null); - assert(primaryVelocity == null - || primaryVelocity == velocity.pixelsPerSecond.dx - || primaryVelocity == velocity.pixelsPerSecond.dy); - } + }) : assert(velocity != null), + assert(primaryVelocity == null + || primaryVelocity == velocity.pixelsPerSecond.dx + || primaryVelocity == velocity.pixelsPerSecond.dy); /// The velocity the pointer was moving when it stopped contacting the screen. /// diff --git a/packages/flutter/lib/src/gestures/lsq_solver.dart b/packages/flutter/lib/src/gestures/lsq_solver.dart index 71ffe7af771..904263b4397 100644 --- a/packages/flutter/lib/src/gestures/lsq_solver.dart +++ b/packages/flutter/lib/src/gestures/lsq_solver.dart @@ -75,10 +75,9 @@ class LeastSquaresSolver { /// Creates a least-squares solver. /// /// The [x], [y], and [w] arguments must not be null. - LeastSquaresSolver(this.x, this.y, this.w) { - assert(x.length == y.length); - assert(y.length == w.length); - } + LeastSquaresSolver(this.x, this.y, this.w) + : assert(x.length == y.length), + assert(y.length == w.length); /// The x-coordinates of each data point. final List x; diff --git a/packages/flutter/lib/src/gestures/multidrag.dart b/packages/flutter/lib/src/gestures/multidrag.dart index d40b81e6733..57f2ac09495 100644 --- a/packages/flutter/lib/src/gestures/multidrag.dart +++ b/packages/flutter/lib/src/gestures/multidrag.dart @@ -27,9 +27,8 @@ abstract class MultiDragPointerState { /// Creates per-pointer state for a [MultiDragGestureRecognizer]. /// /// The [initialPosition] argument must not be null. - MultiDragPointerState(this.initialPosition) { - assert(initialPosition != null); - } + MultiDragPointerState(this.initialPosition) + : assert(initialPosition != null); /// The global coordinates of the pointer when the pointer contacted the screen. final Offset initialPosition; @@ -396,8 +395,9 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Ver } class _DelayedPointerState extends MultiDragPointerState { - _DelayedPointerState(Offset initialPosition, Duration delay) : super(initialPosition) { - assert(delay != null); + _DelayedPointerState(Offset initialPosition, Duration delay) + : assert(delay != null), + super(initialPosition) { _timer = new Timer(delay, _delayPassed); } @@ -481,9 +481,7 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Dela /// can be changed for specific behaviors. DelayedMultiDragGestureRecognizer({ this.delay: kLongPressTimeout - }) { - assert(delay != null); - } + }) : assert(delay != null); /// The amount of time the pointer must remain in the same place for the drag /// to be recognized. diff --git a/packages/flutter/lib/src/gestures/scale.dart b/packages/flutter/lib/src/gestures/scale.dart index 2c459a0647c..5540cd11e48 100644 --- a/packages/flutter/lib/src/gestures/scale.dart +++ b/packages/flutter/lib/src/gestures/scale.dart @@ -32,9 +32,8 @@ class ScaleStartDetails { /// Creates details for [GestureScaleStartCallback]. /// /// The [focalPoint] argument must not be null. - ScaleStartDetails({ this.focalPoint: Offset.zero }) { - assert(focalPoint != null); - } + ScaleStartDetails({ this.focalPoint: Offset.zero }) + : assert(focalPoint != null); /// The initial focal point of the pointers in contact with the screen. /// Reported in global coordinates. @@ -50,10 +49,11 @@ class ScaleUpdateDetails { /// /// The [focalPoint] and [scale] arguments must not be null. The [scale] /// argument must be greater than or equal to zero. - ScaleUpdateDetails({ this.focalPoint: Offset.zero, this.scale: 1.0 }) { - assert(focalPoint != null); - assert(scale != null && scale >= 0.0); - } + ScaleUpdateDetails({ + this.focalPoint: Offset.zero, + this.scale: 1.0, + }) : assert(focalPoint != null), + assert(scale != null && scale >= 0.0); /// The focal point of the pointers in contact with the screen. Reported in /// global coordinates. @@ -72,9 +72,8 @@ class ScaleEndDetails { /// Creates details for [GestureScaleEndCallback]. /// /// The [velocity] argument must not be null. - ScaleEndDetails({ this.velocity: Velocity.zero }) { - assert(velocity != null); - } + ScaleEndDetails({ this.velocity: Velocity.zero }) + : assert(velocity != null); /// The velocity of the last pointer to be lifted off of the screen. final Velocity velocity; diff --git a/packages/flutter/lib/src/gestures/tap.dart b/packages/flutter/lib/src/gestures/tap.dart index 97fbf79f52a..bbe170ae39b 100644 --- a/packages/flutter/lib/src/gestures/tap.dart +++ b/packages/flutter/lib/src/gestures/tap.dart @@ -12,9 +12,8 @@ class TapDownDetails { /// Creates details for a [GestureTapDownCallback]. /// /// The [globalPosition] argument must not be null. - TapDownDetails({ this.globalPosition: Offset.zero }) { - assert(globalPosition != null); - } + TapDownDetails({ this.globalPosition: Offset.zero }) + : assert(globalPosition != null); /// The global position at which the pointer contacted the screen. final Offset globalPosition; @@ -32,9 +31,8 @@ class TapUpDetails { /// Creates details for a [GestureTapUpCallback]. /// /// The [globalPosition] argument must not be null. - TapUpDetails({ this.globalPosition: Offset.zero }) { - assert(globalPosition != null); - } + TapUpDetails({ this.globalPosition: Offset.zero }) + : assert(globalPosition != null); /// The global position at which the pointer contacted the screen. final Offset globalPosition;