Commit e3bab988 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

preview of prefer_asserts_in_initializer_list lint (#10441)

* preview of prefer_asserts_in_initializer_list lint

* fix issue
parent 2aaa7f88
...@@ -57,10 +57,9 @@ class AnimatedList extends StatefulWidget { ...@@ -57,10 +57,9 @@ class AnimatedList extends StatefulWidget {
this.physics, this.physics,
this.shrinkWrap: false, this.shrinkWrap: false,
this.padding, this.padding,
}) : super(key: key) { }) : assert(itemBuilder != null),
assert(itemBuilder != null); assert(initialItemCount != null && initialItemCount >= 0),
assert(initialItemCount != null && initialItemCount >= 0); super(key: key);
}
/// Called, as needed, to build list item widgets. /// Called, as needed, to build list item widgets.
/// ///
......
...@@ -47,12 +47,10 @@ class BannerPainter extends CustomPainter { ...@@ -47,12 +47,10 @@ class BannerPainter extends CustomPainter {
@required this.location, @required this.location,
this.color: _kColor, this.color: _kColor,
this.textStyle: _kTextStyle, this.textStyle: _kTextStyle,
}) { }) : assert(message != null),
assert(message != null); assert(location != null),
assert(location != null); assert(color != null),
assert(color != null); assert(textStyle != null);
assert(textStyle != null);
}
/// The message to show in the banner. /// The message to show in the banner.
final String message; final String message;
......
...@@ -1202,9 +1202,8 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { ...@@ -1202,9 +1202,8 @@ class ConstrainedBox extends SingleChildRenderObjectWidget {
@required this.constraints, @required this.constraints,
Widget child Widget child
}) : assert(constraints != null), }) : assert(constraints != null),
super(key: key, child: child) { assert(constraints.debugAssertIsValid()),
assert(constraints.debugAssertIsValid()); super(key: key, child: child);
}
/// The additional constraints to impose on the child. /// The additional constraints to impose on the child.
final BoxConstraints constraints; final BoxConstraints constraints;
...@@ -2222,9 +2221,8 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -2222,9 +2221,8 @@ class Flex extends MultiChildRenderObjectWidget {
assert(mainAxisAlignment != null), assert(mainAxisAlignment != null),
assert(mainAxisSize != null), assert(mainAxisSize != null),
assert(crossAxisAlignment != null), assert(crossAxisAlignment != null),
super(key: key, children: children) { assert(crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null),// https://github.com/dart-lang/sdk/issues/29278
assert(crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null); // https://github.com/dart-lang/sdk/issues/29278 super(key: key, children: children);
}
/// The direction to use as the main axis. /// The direction to use as the main axis.
/// ///
...@@ -2900,9 +2898,8 @@ class Flow extends MultiChildRenderObjectWidget { ...@@ -2900,9 +2898,8 @@ class Flow extends MultiChildRenderObjectWidget {
Key key, Key key,
@required this.delegate, @required this.delegate,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : super(key: key, children: children) { }) : assert(delegate != null),
assert(delegate != null); super(key: key, children: children);
}
/// The delegate that controls the transformation matrices of the children. /// The delegate that controls the transformation matrices of the children.
final FlowDelegate delegate; final FlowDelegate delegate;
......
...@@ -198,22 +198,21 @@ class Container extends StatelessWidget { ...@@ -198,22 +198,21 @@ class Container extends StatelessWidget {
this.margin, this.margin,
this.transform, this.transform,
this.child, this.child,
}) : decoration = decoration ?? (color != null ? new BoxDecoration(color: color) : null), }) : assert(margin == null || margin.isNonNegative),
assert(padding == null || padding.isNonNegative),
assert(decoration == null || decoration.debugAssertIsValid()),
assert(constraints == null || constraints.debugAssertIsValid()),
assert(color == null || decoration == null,
'Cannot provide both a color and a decoration\n'
'The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".'
),
decoration = decoration ?? (color != null ? new BoxDecoration(color: color) : null),
constraints = constraints =
(width != null || height != null) (width != null || height != null)
? constraints?.tighten(width: width, height: height) ? constraints?.tighten(width: width, height: height)
?? new BoxConstraints.tightFor(width: width, height: height) ?? new BoxConstraints.tightFor(width: width, height: height)
: constraints, : constraints,
super(key: key) { super(key: key);
assert(margin == null || margin.isNonNegative);
assert(padding == null || padding.isNonNegative);
assert(decoration == null || decoration.debugAssertIsValid());
assert(constraints == null || constraints.debugAssertIsValid());
assert(color == null || decoration == null,
'Cannot provide both a color and a decoration\n'
'The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".'
);
}
/// The [child] contained by the container. /// The [child] contained by the container.
/// ///
......
...@@ -129,10 +129,9 @@ class _DismissibleClipper extends CustomClipper<Rect> { ...@@ -129,10 +129,9 @@ class _DismissibleClipper extends CustomClipper<Rect> {
_DismissibleClipper({ _DismissibleClipper({
@required this.axis, @required this.axis,
@required this.moveAnimation @required this.moveAnimation
}) : super(reclip: moveAnimation) { }) : assert(axis != null),
assert(axis != null); assert(moveAnimation != null),
assert(moveAnimation != null); super(reclip: moveAnimation);
}
final Axis axis; final Axis axis;
final Animation<FractionalOffset> moveAnimation; final Animation<FractionalOffset> moveAnimation;
......
...@@ -444,10 +444,9 @@ class _DragAvatar<T> extends Drag { ...@@ -444,10 +444,9 @@ class _DragAvatar<T> extends Drag {
this.feedback, this.feedback,
this.feedbackOffset: Offset.zero, this.feedbackOffset: Offset.zero,
this.onDragEnd this.onDragEnd
}) { }) : assert(overlayState != null),
assert(overlayState != null); assert(dragStartPoint != null),
assert(dragStartPoint != null); assert(feedbackOffset != null) {
assert(feedbackOffset != null);
_entry = new OverlayEntry(builder: _build); _entry = new OverlayEntry(builder: _build);
overlayState.insert(_entry); overlayState.insert(_entry);
_position = initialPosition; _position = initialPosition;
......
...@@ -1573,9 +1573,8 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { ...@@ -1573,9 +1573,8 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
/// objects. /// objects.
MultiChildRenderObjectWidget({ Key key, this.children: const <Widget>[] }) MultiChildRenderObjectWidget({ Key key, this.children: const <Widget>[] })
: assert(children != null), : assert(children != null),
super(key: key) { assert(!children.any((Widget child) => child == null)), // https://github.com/dart-lang/sdk/issues/29276
assert(!children.any((Widget child) => child == null)); // https://github.com/dart-lang/sdk/issues/29276 super(key: key);
}
/// The widgets below this widget in the tree. /// The widgets below this widget in the tree.
/// ///
...@@ -2375,9 +2374,9 @@ abstract class Element implements BuildContext { ...@@ -2375,9 +2374,9 @@ abstract class Element implements BuildContext {
/// Creates an element that uses the given widget as its configuration. /// Creates an element that uses the given widget as its configuration.
/// ///
/// Typically called by an override of [Widget.createElement]. /// Typically called by an override of [Widget.createElement].
Element(Widget widget) : _widget = widget { Element(Widget widget)
assert(widget != null); : assert(widget != null),
} _widget = widget;
Element _parent; Element _parent;
...@@ -4363,9 +4362,9 @@ class SingleChildRenderObjectElement extends RenderObjectElement { ...@@ -4363,9 +4362,9 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
/// are expected to inherit from [MultiChildRenderObjectWidget]. /// are expected to inherit from [MultiChildRenderObjectWidget].
class MultiChildRenderObjectElement extends RenderObjectElement { class MultiChildRenderObjectElement extends RenderObjectElement {
/// Creates an element that uses the given widget as its configuration. /// Creates an element that uses the given widget as its configuration.
MultiChildRenderObjectElement(MultiChildRenderObjectWidget widget) : super(widget) { MultiChildRenderObjectElement(MultiChildRenderObjectWidget widget)
assert(!debugChildrenHaveDuplicateKeys(widget, widget.children)); : assert(!debugChildrenHaveDuplicateKeys(widget, widget.children)),
} super(widget);
@override @override
MultiChildRenderObjectWidget get widget => super.widget; MultiChildRenderObjectWidget get widget => super.widget;
......
...@@ -98,32 +98,31 @@ class GestureDetector extends StatelessWidget { ...@@ -98,32 +98,31 @@ class GestureDetector extends StatelessWidget {
this.onScaleEnd, this.onScaleEnd,
this.behavior, this.behavior,
this.excludeFromSemantics: false this.excludeFromSemantics: false
}) : super(key: key) { }) : assert(excludeFromSemantics != null),
assert(excludeFromSemantics != null); assert(() {
assert(() { final bool haveVerticalDrag = onVerticalDragStart != null || onVerticalDragUpdate != null || onVerticalDragEnd != null;
final bool haveVerticalDrag = onVerticalDragStart != null || onVerticalDragUpdate != null || onVerticalDragEnd != null; final bool haveHorizontalDrag = onHorizontalDragStart != null || onHorizontalDragUpdate != null || onHorizontalDragEnd != null;
final bool haveHorizontalDrag = onHorizontalDragStart != null || onHorizontalDragUpdate != null || onHorizontalDragEnd != null; final bool havePan = onPanStart != null || onPanUpdate != null || onPanEnd != null;
final bool havePan = onPanStart != null || onPanUpdate != null || onPanEnd != null; final bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null;
final bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null; if (havePan || haveScale) {
if (havePan || haveScale) { if (havePan && haveScale) {
if (havePan && haveScale) { throw new FlutterError(
throw new FlutterError( 'Incorrect GestureDetector arguments.\n'
'Incorrect GestureDetector arguments.\n' 'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan. Just use the scale gesture recognizer.'
'Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan. Just use the scale gesture recognizer.' );
); }
} final String recognizer = havePan ? 'pan' : 'scale';
final String recognizer = havePan ? 'pan' : 'scale'; if (haveVerticalDrag && haveHorizontalDrag) {
if (haveVerticalDrag && haveHorizontalDrag) { throw new FlutterError(
throw new FlutterError( 'Incorrect GestureDetector arguments.\n'
'Incorrect GestureDetector arguments.\n' 'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer '
'Simultaneously having a vertical drag gesture recognizer, a horizontal drag gesture recognizer, and a $recognizer gesture recognizer ' 'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.'
'will result in the $recognizer gesture recognizer being ignored, since the other two will catch all drags.' );
); }
} }
} return true;
return true; }),
}); super(key: key);
}
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
final Widget child; final Widget child;
......
...@@ -180,9 +180,7 @@ class _HeroFlightManifest { ...@@ -180,9 +180,7 @@ class _HeroFlightManifest {
@required this.fromHero, @required this.fromHero,
@required this.toHero, @required this.toHero,
@required this.createRectTween, @required this.createRectTween,
}) { }) : assert(fromHero.widget.tag == toHero.widget.tag);
assert(fromHero.widget.tag == toHero.widget.tag);
}
final _HeroFlightType type; final _HeroFlightType type;
final OverlayState overlay; final OverlayState overlay;
......
...@@ -318,22 +318,21 @@ class AnimatedContainer extends ImplicitlyAnimatedWidget { ...@@ -318,22 +318,21 @@ class AnimatedContainer extends ImplicitlyAnimatedWidget {
this.child, this.child,
Curve curve: Curves.linear, Curve curve: Curves.linear,
@required Duration duration, @required Duration duration,
}) : decoration = decoration ?? (color != null ? new BoxDecoration(color: color) : null), }) : assert(margin == null || margin.isNonNegative),
assert(padding == null || padding.isNonNegative),
assert(decoration == null || decoration.debugAssertIsValid()),
assert(constraints == null || constraints.debugAssertIsValid()),
assert(color == null || decoration == null,
'Cannot provide both a color and a decoration\n'
'The color argument is just a shorthand for "decoration: new BoxDecoration(backgroundColor: color)".'
),
decoration = decoration ?? (color != null ? new BoxDecoration(color: color) : null),
constraints = constraints =
(width != null || height != null) (width != null || height != null)
? constraints?.tighten(width: width, height: height) ? constraints?.tighten(width: width, height: height)
?? new BoxConstraints.tightFor(width: width, height: height) ?? new BoxConstraints.tightFor(width: width, height: height)
: constraints, : constraints,
super(key: key, curve: curve, duration: duration) { super(key: key, curve: curve, duration: duration);
assert(margin == null || margin.isNonNegative);
assert(padding == null || padding.isNonNegative);
assert(decoration == null || decoration.debugAssertIsValid());
assert(constraints == null || constraints.debugAssertIsValid());
assert(color == null || decoration == null,
'Cannot provide both a color and a decoration\n'
'The color argument is just a shorthand for "decoration: new BoxDecoration(backgroundColor: color)".'
);
}
/// The [child] contained by the container. /// The [child] contained by the container.
/// ///
......
...@@ -256,8 +256,8 @@ class NavigatorObserver { ...@@ -256,8 +256,8 @@ class NavigatorObserver {
abstract class NavigationGestureController { abstract class NavigationGestureController {
/// Configures the NavigationGestureController and tells the given [Navigator] that /// Configures the NavigationGestureController and tells the given [Navigator] that
/// a gesture has started. /// a gesture has started.
NavigationGestureController(this._navigator) { NavigationGestureController(this._navigator)
assert(_navigator != null); : assert(_navigator != null) {
// Disable Hero transitions until the gesture is complete. // Disable Hero transitions until the gesture is complete.
_navigator.didStartUserGesture(); _navigator.didStartUserGesture();
} }
......
...@@ -38,12 +38,11 @@ class NestedScrollView extends StatefulWidget { ...@@ -38,12 +38,11 @@ class NestedScrollView extends StatefulWidget {
this.physics, this.physics,
@required this.headerSliverBuilder, @required this.headerSliverBuilder,
@required this.body, @required this.body,
}) : super(key: key) { }) : assert(scrollDirection != null),
assert(scrollDirection != null); assert(reverse != null),
assert(reverse != null); assert(headerSliverBuilder != null),
assert(headerSliverBuilder != null); assert(body != null),
assert(body != null); super(key: key);
}
// TODO(ianh): we should expose a controller so you can call animateTo, etc. // TODO(ianh): we should expose a controller so you can call animateTo, etc.
...@@ -782,10 +781,9 @@ class _NestedOuterBallisticScrollActivity extends BallisticScrollActivity { ...@@ -782,10 +781,9 @@ class _NestedOuterBallisticScrollActivity extends BallisticScrollActivity {
this.metrics, this.metrics,
Simulation simulation, Simulation simulation,
TickerProvider vsync, TickerProvider vsync,
) : super(position, simulation, vsync) { ) : assert(metrics.minRange != metrics.maxRange),
assert(metrics.minRange != metrics.maxRange); assert(metrics.maxRange > metrics.minRange),
assert(metrics.maxRange > metrics.minRange); super(position, simulation, vsync);
}
final _NestedScrollCoordinator coordinator; final _NestedScrollCoordinator coordinator;
final _NestedScrollMetrics metrics; final _NestedScrollMetrics metrics;
......
...@@ -62,11 +62,11 @@ class OverlayEntry { ...@@ -62,11 +62,11 @@ class OverlayEntry {
@required this.builder, @required this.builder,
bool opaque: false, bool opaque: false,
bool maintainState: false, bool maintainState: false,
}) : _opaque = opaque, _maintainState = maintainState { }) : assert(builder != null),
assert(builder != null); assert(opaque != null),
assert(opaque != null); assert(maintainState != null),
assert(maintainState != null); _opaque = opaque,
} _maintainState = maintainState;
/// This entry will include the widget built by this builder in the overlay at /// This entry will include the widget built by this builder in the overlay at
/// the entry's position. /// the entry's position.
...@@ -154,9 +154,9 @@ class OverlayEntry { ...@@ -154,9 +154,9 @@ class OverlayEntry {
} }
class _OverlayEntry extends StatefulWidget { class _OverlayEntry extends StatefulWidget {
_OverlayEntry(this.entry) : super(key: entry._key) { _OverlayEntry(this.entry)
assert(entry != null); : assert(entry != null),
} super(key: entry._key);
final OverlayEntry entry; final OverlayEntry entry;
...@@ -388,10 +388,8 @@ class _Theatre extends RenderObjectWidget { ...@@ -388,10 +388,8 @@ class _Theatre extends RenderObjectWidget {
_Theatre({ _Theatre({
this.onstage, this.onstage,
@required this.offstage, @required this.offstage,
}) { }) : assert(offstage != null),
assert(offstage != null); assert(!offstage.any((Widget child) => child == null));
assert(!offstage.any((Widget child) => child == null));
}
final Stack onstage; final Stack onstage;
...@@ -405,9 +403,9 @@ class _Theatre extends RenderObjectWidget { ...@@ -405,9 +403,9 @@ class _Theatre extends RenderObjectWidget {
} }
class _TheatreElement extends RenderObjectElement { class _TheatreElement extends RenderObjectElement {
_TheatreElement(_Theatre widget) : super(widget) { _TheatreElement(_Theatre widget)
assert(!debugChildrenHaveDuplicateKeys(widget, widget.offstage)); : assert(!debugChildrenHaveDuplicateKeys(widget, widget.offstage)),
} super(widget);
@override @override
_Theatre get widget => super.widget; _Theatre get widget => super.widget;
......
...@@ -225,11 +225,11 @@ class _GlowController extends ChangeNotifier { ...@@ -225,11 +225,11 @@ class _GlowController extends ChangeNotifier {
@required TickerProvider vsync, @required TickerProvider vsync,
@required Color color, @required Color color,
@required Axis axis, @required Axis axis,
}) : _color = color, }) : assert(vsync != null),
assert(color != null),
assert(axis != null),
_color = color,
_axis = axis { _axis = axis {
assert(vsync != null);
assert(color != null);
assert(axis != null);
_glowController = new AnimationController(vsync: vsync) _glowController = new AnimationController(vsync: vsync)
..addStatusListener(_changePhase); ..addStatusListener(_changePhase);
final Animation<double> decelerator = new CurvedAnimation( final Animation<double> decelerator = new CurvedAnimation(
......
...@@ -42,11 +42,9 @@ class PageController extends ScrollController { ...@@ -42,11 +42,9 @@ class PageController extends ScrollController {
PageController({ PageController({
this.initialPage: 0, this.initialPage: 0,
this.viewportFraction: 1.0, this.viewportFraction: 1.0,
}) { }) : assert(initialPage != null),
assert(initialPage != null); assert(viewportFraction != null),
assert(viewportFraction != null); assert(viewportFraction > 0.0);
assert(viewportFraction > 0.0);
}
/// The page to show when first creating the [PageView]. /// The page to show when first creating the [PageView].
final int initialPage; final int initialPage;
...@@ -154,18 +152,17 @@ class _PagePosition extends ScrollPositionWithSingleContext { ...@@ -154,18 +152,17 @@ class _PagePosition extends ScrollPositionWithSingleContext {
this.initialPage: 0, this.initialPage: 0,
double viewportFraction: 1.0, double viewportFraction: 1.0,
ScrollPosition oldPosition, ScrollPosition oldPosition,
}) : _viewportFraction = viewportFraction, }) : assert(initialPage != null),
assert(viewportFraction != null),
assert(viewportFraction > 0.0),
_viewportFraction = viewportFraction,
_pageToUseOnStartup = initialPage.toDouble(), _pageToUseOnStartup = initialPage.toDouble(),
super( super(
physics: physics, physics: physics,
context: context, context: context,
initialPixels: null, initialPixels: null,
oldPosition: oldPosition, oldPosition: oldPosition,
) { );
assert(initialPage != null);
assert(viewportFraction != null);
assert(viewportFraction > 0.0);
}
final int initialPage; final int initialPage;
double _pageToUseOnStartup; double _pageToUseOnStartup;
...@@ -358,9 +355,9 @@ class PageView extends StatefulWidget { ...@@ -358,9 +355,9 @@ class PageView extends StatefulWidget {
this.physics, this.physics,
this.onPageChanged, this.onPageChanged,
@required this.childrenDelegate, @required this.childrenDelegate,
}) : controller = controller ?? _defaultPageController, super(key: key) { }) : assert(childrenDelegate != null),
assert(childrenDelegate != null); controller = controller ?? _defaultPageController,
} super(key: key);
/// The axis along which the page view scrolls. /// The axis along which the page view scrolls.
/// ///
......
...@@ -76,13 +76,12 @@ class PageRouteBuilder<T> extends PageRoute<T> { ...@@ -76,13 +76,12 @@ class PageRouteBuilder<T> extends PageRoute<T> {
this.barrierDismissible: false, this.barrierDismissible: false,
this.barrierColor: null, this.barrierColor: null,
this.maintainState: true, this.maintainState: true,
}) : super(settings: settings) { }) : assert(pageBuilder != null),
assert(pageBuilder != null); assert(transitionsBuilder != null),
assert(transitionsBuilder != null); assert(opaque != null),
assert(opaque != null); assert(barrierDismissible != null),
assert(barrierDismissible != null); assert(maintainState != null),
assert(maintainState != null); super(settings: settings);
}
/// Used build the route's primary contents. /// Used build the route's primary contents.
/// ///
......
...@@ -215,10 +215,10 @@ class ScrollDragController implements Drag { ...@@ -215,10 +215,10 @@ class ScrollDragController implements Drag {
@required ScrollActivityDelegate delegate, @required ScrollActivityDelegate delegate,
@required DragStartDetails details, @required DragStartDetails details,
this.onDragCanceled, this.onDragCanceled,
}) : _delegate = delegate, _lastDetails = details { }) : assert(delegate != null),
assert(delegate != null); assert(details != null),
assert(details != null); _delegate = delegate,
} _lastDetails = details;
/// The object that will actuate the scroll view as the user drags. /// The object that will actuate the scroll view as the user drags.
ScrollActivityDelegate get delegate => _delegate; ScrollActivityDelegate get delegate => _delegate;
...@@ -466,12 +466,12 @@ class DrivenScrollActivity extends ScrollActivity { ...@@ -466,12 +466,12 @@ class DrivenScrollActivity extends ScrollActivity {
@required Duration duration, @required Duration duration,
@required Curve curve, @required Curve curve,
@required TickerProvider vsync, @required TickerProvider vsync,
}) : super(delegate) { }) : assert(from != null),
assert(from != null); assert(to != null),
assert(to != null); assert(duration != null),
assert(duration != null); assert(duration > Duration.ZERO),
assert(duration > Duration.ZERO); assert(curve != null),
assert(curve != null); super(delegate) {
_completer = new Completer<Null>(); _completer = new Completer<Null>();
_controller = new AnimationController.unbounded( _controller = new AnimationController.unbounded(
value: from, value: from,
......
...@@ -43,9 +43,7 @@ class ScrollController extends ChangeNotifier { ...@@ -43,9 +43,7 @@ class ScrollController extends ChangeNotifier {
ScrollController({ ScrollController({
this.initialScrollOffset: 0.0, this.initialScrollOffset: 0.0,
this.debugLabel, this.debugLabel,
}) { }) : assert(initialScrollOffset != null);
assert(initialScrollOffset != null);
}
/// The initial value to use for [offset]. /// The initial value to use for [offset].
/// ///
......
...@@ -171,12 +171,11 @@ class OverscrollNotification extends ScrollNotification { ...@@ -171,12 +171,11 @@ class OverscrollNotification extends ScrollNotification {
this.dragDetails, this.dragDetails,
@required this.overscroll, @required this.overscroll,
this.velocity: 0.0, this.velocity: 0.0,
}) : super(metrics: metrics, context: context) { }) : assert(overscroll != null),
assert(overscroll != null); assert(overscroll.isFinite),
assert(overscroll.isFinite); assert(overscroll != 0.0),
assert(overscroll != 0.0); assert(velocity != null),
assert(velocity != null); super(metrics: metrics, context: context);
}
/// If the [Scrollable] overscrolled because of a drag, the details about that /// If the [Scrollable] overscrolled because of a drag, the details about that
/// drag update. /// drag update.
......
...@@ -66,10 +66,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { ...@@ -66,10 +66,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
@required this.context, @required this.context,
ScrollPosition oldPosition, ScrollPosition oldPosition,
this.debugLabel, this.debugLabel,
}) { }) : assert(physics != null),
assert(physics != null); assert(context != null),
assert(context != null); assert(context.vsync != null) {
assert(context.vsync != null);
if (oldPosition != null) if (oldPosition != null)
absorb(oldPosition); absorb(oldPosition);
restoreScrollOffset(); restoreScrollOffset();
......
...@@ -35,14 +35,13 @@ class BouncingScrollSimulation extends Simulation { ...@@ -35,14 +35,13 @@ class BouncingScrollSimulation extends Simulation {
@required this.trailingExtent, @required this.trailingExtent,
@required this.spring, @required this.spring,
Tolerance tolerance: Tolerance.defaultTolerance, Tolerance tolerance: Tolerance.defaultTolerance,
}) : super(tolerance: tolerance) { }) : assert(position != null),
assert(position != null); assert(velocity != null),
assert(velocity != null); assert(leadingExtent != null),
assert(leadingExtent != null); assert(trailingExtent != null),
assert(trailingExtent != null); assert(leadingExtent <= trailingExtent),
assert(leadingExtent <= trailingExtent); assert(spring != null),
assert(spring != null); super(tolerance: tolerance) {
if (position < leadingExtent) { if (position < leadingExtent) {
_springSimulation = _underscrollSimulation(position, velocity); _springSimulation = _underscrollSimulation(position, velocity);
_springTime = double.NEGATIVE_INFINITY; _springTime = double.NEGATIVE_INFINITY;
......
...@@ -51,17 +51,15 @@ abstract class ScrollView extends StatelessWidget { ...@@ -51,17 +51,15 @@ abstract class ScrollView extends StatelessWidget {
bool primary, bool primary,
ScrollPhysics physics, ScrollPhysics physics,
this.shrinkWrap: false, this.shrinkWrap: false,
}) : primary = primary ?? controller == null && scrollDirection == Axis.vertical, }) : assert(reverse != null),
physics = physics ?? (primary == true || (primary == null && controller == null && scrollDirection == Axis.vertical) ? const AlwaysScrollableScrollPhysics() : null), assert(shrinkWrap != null),
super(key: key) { assert(!(controller != null && primary == true),
assert(reverse != null);
assert(shrinkWrap != null);
assert(this.primary != null);
assert(controller == null || !this.primary,
'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. ' 'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. '
'You cannot both set primary to true and pass an explicit controller.' 'You cannot both set primary to true and pass an explicit controller.'
); ),
} primary = primary ?? controller == null && scrollDirection == Axis.vertical,
physics = physics ?? (primary == true || (primary == null && controller == null && scrollDirection == Axis.vertical) ? const AlwaysScrollableScrollPhysics() : null),
super(key: key);
/// The axis along which the scroll view scrolls. /// The axis along which the scroll view scrolls.
/// ///
...@@ -511,18 +509,17 @@ class ListView extends BoxScrollView { ...@@ -511,18 +509,17 @@ class ListView extends BoxScrollView {
EdgeInsets padding, EdgeInsets padding,
this.itemExtent, this.itemExtent,
@required this.childrenDelegate, @required this.childrenDelegate,
}) : super( }) : assert(childrenDelegate != null),
key: key, super(
scrollDirection: scrollDirection, key: key,
reverse: reverse, scrollDirection: scrollDirection,
controller: controller, reverse: reverse,
primary: primary, controller: controller,
physics: physics, primary: primary,
shrinkWrap: shrinkWrap, physics: physics,
padding: padding, shrinkWrap: shrinkWrap,
) { padding: padding,
assert(childrenDelegate != null); );
}
/// If non-null, forces the children to have the given extent in the scroll /// If non-null, forces the children to have the given extent in the scroll
/// direction. /// direction.
...@@ -607,18 +604,18 @@ class GridView extends BoxScrollView { ...@@ -607,18 +604,18 @@ class GridView extends BoxScrollView {
EdgeInsets padding, EdgeInsets padding,
@required this.gridDelegate, @required this.gridDelegate,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : childrenDelegate = new SliverChildListDelegate(children), super( }) : assert(gridDelegate != null),
key: key, childrenDelegate = new SliverChildListDelegate(children),
scrollDirection: scrollDirection, super(
reverse: reverse, key: key,
controller: controller, scrollDirection: scrollDirection,
primary: primary, reverse: reverse,
physics: physics, controller: controller,
shrinkWrap: shrinkWrap, primary: primary,
padding: padding, physics: physics,
) { shrinkWrap: shrinkWrap,
assert(gridDelegate != null); padding: padding,
} );
/// Creates a scrollable, 2D array of widgets that are created on demand. /// Creates a scrollable, 2D array of widgets that are created on demand.
/// ///
...@@ -645,18 +642,18 @@ class GridView extends BoxScrollView { ...@@ -645,18 +642,18 @@ class GridView extends BoxScrollView {
@required this.gridDelegate, @required this.gridDelegate,
@required IndexedWidgetBuilder itemBuilder, @required IndexedWidgetBuilder itemBuilder,
int itemCount, int itemCount,
}) : childrenDelegate = new SliverChildBuilderDelegate(itemBuilder, childCount: itemCount), super( }) : assert(gridDelegate != null),
key: key, childrenDelegate = new SliverChildBuilderDelegate(itemBuilder, childCount: itemCount),
scrollDirection: scrollDirection, super(
reverse: reverse, key: key,
controller: controller, scrollDirection: scrollDirection,
primary: primary, reverse: reverse,
physics: physics, controller: controller,
shrinkWrap: shrinkWrap, primary: primary,
padding: padding, physics: physics,
) { shrinkWrap: shrinkWrap,
assert(gridDelegate != null); padding: padding,
} );
/// Creates a scrollable, 2D array of widgets with both a custom /// Creates a scrollable, 2D array of widgets with both a custom
/// [SliverGridDelegate] and a custom [SliverChildDelegate]. /// [SliverGridDelegate] and a custom [SliverChildDelegate].
...@@ -676,19 +673,18 @@ class GridView extends BoxScrollView { ...@@ -676,19 +673,18 @@ class GridView extends BoxScrollView {
EdgeInsets padding, EdgeInsets padding,
@required this.gridDelegate, @required this.gridDelegate,
@required this.childrenDelegate, @required this.childrenDelegate,
}) : super( }) : assert(gridDelegate != null),
key: key, assert(childrenDelegate != null),
scrollDirection: scrollDirection, super(
reverse: reverse, key: key,
controller: controller, scrollDirection: scrollDirection,
primary: primary, reverse: reverse,
physics: physics, controller: controller,
shrinkWrap: shrinkWrap, primary: primary,
padding: padding, physics: physics,
) { shrinkWrap: shrinkWrap,
assert(gridDelegate != null); padding: padding,
assert(childrenDelegate != null); );
}
/// Creates a scrollable, 2D array of widgets with a fixed number of tiles in /// Creates a scrollable, 2D array of widgets with a fixed number of tiles in
/// the cross axis. /// the cross axis.
......
...@@ -49,15 +49,13 @@ class SingleChildScrollView extends StatelessWidget { ...@@ -49,15 +49,13 @@ class SingleChildScrollView extends StatelessWidget {
this.physics, this.physics,
this.controller, this.controller,
this.child, this.child,
}) : primary = primary ?? controller == null && scrollDirection == Axis.vertical, }) : assert(scrollDirection != null),
super(key: key) { assert(!(controller != null && primary == true),
assert(scrollDirection != null); 'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. '
assert(this.primary != null); 'You cannot both set primary to true and pass an explicit controller.'
assert(controller == null || !this.primary, ),
'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. ' primary = primary ?? controller == null && scrollDirection == Axis.vertical,
'You cannot both set primary to true and pass an explicit controller.' super(key: key);
);
}
/// The axis along which the scroll view scrolls. /// The axis along which the scroll view scrolls.
/// ///
...@@ -180,10 +178,10 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix ...@@ -180,10 +178,10 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
AxisDirection axisDirection: AxisDirection.down, AxisDirection axisDirection: AxisDirection.down,
@required ViewportOffset offset, @required ViewportOffset offset,
RenderBox child, RenderBox child,
}) : _axisDirection = axisDirection, }) : assert(axisDirection != null),
assert(offset != null),
_axisDirection = axisDirection,
_offset = offset { _offset = offset {
assert(axisDirection != null);
assert(offset != null);
this.child = child; this.child = child;
} }
......
...@@ -58,9 +58,8 @@ class _RenderSizeChangedWithCallback extends RenderProxyBox { ...@@ -58,9 +58,8 @@ class _RenderSizeChangedWithCallback extends RenderProxyBox {
_RenderSizeChangedWithCallback({ _RenderSizeChangedWithCallback({
RenderBox child, RenderBox child,
@required this.onLayoutChangedCallback @required this.onLayoutChangedCallback
}) : super(child) { }) : assert(onLayoutChangedCallback != null),
assert(onLayoutChangedCallback != null); super(child);
}
// There's a 1:1 relationship between the _RenderSizeChangedWithCallback and // There's a 1:1 relationship between the _RenderSizeChangedWithCallback and
// the `context` that is captured by the closure created by createRenderObject // the `context` that is captured by the closure created by createRenderObject
......
...@@ -100,22 +100,44 @@ class Table extends RenderObjectWidget { ...@@ -100,22 +100,44 @@ class Table extends RenderObjectWidget {
this.border, this.border,
this.defaultVerticalAlignment: TableCellVerticalAlignment.top, this.defaultVerticalAlignment: TableCellVerticalAlignment.top,
this.textBaseline this.textBaseline
}) : _rowDecorations = children.any((TableRow row) => row.decoration != null) }) : assert(children != null),
? children.map<Decoration>((TableRow row) => row.decoration).toList(growable: false) assert(defaultColumnWidth != null),
: null, assert(defaultVerticalAlignment != null),
assert(() {
if (children.any((TableRow row) => row.children.any((Widget cell) => cell == null))) {
throw new FlutterError(
'One of the children of one of the rows of the table was null.\n'
'The children of a TableRow must not be null.'
);
}
return true;
}),
assert(() {
if (children.any((TableRow row1) => row1.key != null && children.any((TableRow row2) => row1 != row2 && row1.key == row2.key))) {
throw new FlutterError(
'Two or more TableRow children of this Table had the same key.\n'
'All the keyed TableRow children of a Table must have different Keys.'
);
}
return true;
}),
assert(() {
if (children.isNotEmpty) {
final int cellCount = children.first.children.length;
if (children.any((TableRow row) => row.children.length != cellCount)) {
throw new FlutterError(
'Table contains irregular row lengths.\n'
'Every TableRow in a Table must have the same number of children, so that every cell is filled. '
'Otherwise, the table will contain holes.'
);
}
}
return true;
}),
_rowDecorations = children.any((TableRow row) => row.decoration != null)
? children.map<Decoration>((TableRow row) => row.decoration).toList(growable: false)
: null,
super(key: key) { super(key: key) {
assert(children != null);
assert(defaultColumnWidth != null);
assert(defaultVerticalAlignment != null);
assert(() {
if (children.any((TableRow row) => row.children.any((Widget cell) => cell == null))) {
throw new FlutterError(
'One of the children of one of the rows of the table was null.\n'
'The children of a TableRow must not be null.'
);
}
return true;
});
assert(() { assert(() {
final List<Widget> flatChildren = children.expand((TableRow row) => row.children).toList(growable: false); final List<Widget> flatChildren = children.expand((TableRow row) => row.children).toList(growable: false);
if (debugChildrenHaveDuplicateKeys(this, flatChildren)) { if (debugChildrenHaveDuplicateKeys(this, flatChildren)) {
...@@ -128,28 +150,6 @@ class Table extends RenderObjectWidget { ...@@ -128,28 +150,6 @@ class Table extends RenderObjectWidget {
} }
return true; return true;
}); });
assert(() {
if (children.any((TableRow row1) => row1.key != null && children.any((TableRow row2) => row1 != row2 && row1.key == row2.key))) {
throw new FlutterError(
'Two or more TableRow children of this Table had the same key.\n'
'All the keyed TableRow children of a Table must have different Keys.'
);
}
return true;
});
assert(() {
if (children.isNotEmpty) {
final int cellCount = children.first.children.length;
if (children.any((TableRow row) => row.children.length != cellCount)) {
throw new FlutterError(
'Table contains irregular row lengths.\n'
'Every TableRow in a Table must have the same number of children, so that every cell is filled. '
'Otherwise, the table will contain holes.'
);
}
}
return true;
});
} }
/// The rows of the table. /// The rows of the table.
......
...@@ -95,9 +95,9 @@ class TextSelectionOverlay implements TextSelectionDelegate { ...@@ -95,9 +95,9 @@ class TextSelectionOverlay implements TextSelectionDelegate {
this.renderObject, this.renderObject,
this.onSelectionOverlayChanged, this.onSelectionOverlayChanged,
this.selectionControls, this.selectionControls,
}): _value = value { }): assert(value != null),
assert(value != null); assert(context != null),
assert(context != null); _value = value {
final OverlayState overlay = Overlay.of(context); final OverlayState overlay = Overlay.of(context);
assert(overlay != null); assert(overlay != null);
_handleController = new AnimationController(duration: _kFadeDuration, vsync: overlay); _handleController = new AnimationController(duration: _kFadeDuration, vsync: overlay);
......
...@@ -14,9 +14,8 @@ class Title extends StatelessWidget { ...@@ -14,9 +14,8 @@ class Title extends StatelessWidget {
this.title, this.title,
this.color, this.color,
@required this.child, @required this.child,
}) : super(key: key) { }) : assert(color == null || color.alpha == 0xFF),
assert(color == null || color.alpha == 0xFF); super(key: key);
}
/// A one-line description of this app for use in the window manager. /// A one-line description of this app for use in the window manager.
final String title; final String title;
......
...@@ -56,10 +56,10 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -56,10 +56,10 @@ class Viewport extends MultiChildRenderObjectWidget {
@required this.offset, @required this.offset,
this.center, this.center,
List<Widget> slivers: const <Widget>[], List<Widget> slivers: const <Widget>[],
}) : super(key: key, children: slivers) { }) : assert(offset != null),
assert(offset != null); assert(slivers != null),
assert(center == null || children.where((Widget child) => child.key == center).length == 1); assert(center == null || slivers.where((Widget child) => child.key == center).length == 1),
} super(key: key, children: slivers);
/// The direction in which the [offset]'s [ViewportOffset.pixels] increases. /// The direction in which the [offset]'s [ViewportOffset.pixels] increases.
/// ///
...@@ -203,9 +203,8 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -203,9 +203,8 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
this.axisDirection: AxisDirection.down, this.axisDirection: AxisDirection.down,
@required this.offset, @required this.offset,
List<Widget> slivers: const <Widget>[], List<Widget> slivers: const <Widget>[],
}) : super(key: key, children: slivers) { }) : assert(offset != null),
assert(offset != null); super(key: key, children: slivers);
}
/// The direction in which the [offset]'s [ViewportOffset.pixels] increases. /// The direction in which the [offset]'s [ViewportOffset.pixels] increases.
/// ///
......
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