From 0b2fb13269b86a71316982ddc92b026c8ca56536 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 9 May 2017 17:56:49 -0700 Subject: [PATCH] Add const non-null asserts where required (#9939) Also fixes a small typo. --- packages/flutter/lib/src/gestures/drag_details.dart | 1 + .../flutter/lib/src/gestures/velocity_tracker.dart | 13 ++++++++++--- packages/flutter/lib/src/material/data_table.dart | 9 +++++---- packages/flutter/lib/src/material/icon_button.dart | 6 +++++- packages/flutter/lib/src/material/list_tile.dart | 1 + .../lib/src/material/mergeable_material.dart | 2 +- .../flutter/lib/src/material/tab_controller.dart | 3 ++- packages/flutter/lib/src/painting/box_painter.dart | 9 ++++++--- packages/flutter/lib/src/painting/colors.dart | 6 +++++- packages/flutter/lib/src/painting/text_style.dart | 2 +- 10 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packages/flutter/lib/src/gestures/drag_details.dart b/packages/flutter/lib/src/gestures/drag_details.dart index a8f5a06f91..9cdfdb0131 100644 --- a/packages/flutter/lib/src/gestures/drag_details.dart +++ b/packages/flutter/lib/src/gestures/drag_details.dart @@ -100,6 +100,7 @@ class DragUpdateDetails { 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)); diff --git a/packages/flutter/lib/src/gestures/velocity_tracker.dart b/packages/flutter/lib/src/gestures/velocity_tracker.dart index a9c53a9ce3..e1081ddabc 100644 --- a/packages/flutter/lib/src/gestures/velocity_tracker.dart +++ b/packages/flutter/lib/src/gestures/velocity_tracker.dart @@ -13,7 +13,7 @@ class Velocity { /// Creates a velocity. /// /// The [pixelsPerSecond] argument must not be null. - const Velocity({ this.pixelsPerSecond }); + const Velocity({ this.pixelsPerSecond }) : assert(pixelsPerSecond != null); /// A velocity that isn't moving at all. static const Velocity zero = const Velocity(pixelsPerSecond: Offset.zero); @@ -87,12 +87,17 @@ class Velocity { /// useful velocity operations. class VelocityEstimate { /// Creates a dimensional velocity estimate. + /// + /// [pixelsPerSecond], [confidence], [duration], and [offset] must not be null. const VelocityEstimate({ this.pixelsPerSecond, this.confidence, this.duration, this.offset, - }); + }) : assert(pixelsPerSecond != null), + assert(confidence != null), + assert(duration != null), + assert(offset != null); /// The number of pixels per second of velocity in the x and y directions. final Offset pixelsPerSecond; @@ -116,7 +121,9 @@ class VelocityEstimate { } class _PointAtTime { - const _PointAtTime(this.point, this.time); + const _PointAtTime(this.point, this.time) + : assert(point != null), + assert(time != null); final Duration time; final Offset point; diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index 42bb699aca..a08f0581f6 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -40,7 +40,7 @@ class DataColumn { this.tooltip, this.numeric: false, this.onSort - }); + }) : assert(label != null); /// The column heading. /// @@ -92,7 +92,7 @@ class DataRow { this.selected: false, this.onSelectChanged, this.cells - }); + }) : assert(cells != null); /// Creates the configuration for a row of a [DataTable], deriving /// the key from a row index. @@ -103,7 +103,8 @@ class DataRow { this.selected: false, this.onSelectChanged, this.cells - }) : key = new ValueKey(index); + }) : assert(cells != null), + key = new ValueKey(index); /// A [Key] that uniquely identifies this row. This is used to /// ensure that if a row is added or removed, any stateful widgets @@ -167,7 +168,7 @@ class DataCell { this.placeholder: false, this.showEditIcon: false, this.onTap, - }); + }) : assert(child != null); /// A cell that has no content and has zero width and height. static final DataCell empty = new DataCell(new Container(width: 0.0, height: 0.0)); diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 5159968424..5658c9d80a 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -69,7 +69,11 @@ class IconButton extends StatelessWidget { this.disabledColor, @required this.onPressed, this.tooltip - }) : super(key: key); + }) : assert(iconSize != null), + assert(padding != null), + assert(alignment != null), + assert(icon != null), + super(key: key); /// The size of the icon inside the button. /// diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 7c984946af..a49658da13 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -137,6 +137,7 @@ class ListTile extends StatelessWidget { }) : assert(isThreeLine != null), assert(enabled != null), assert(selected != null), + assert(!isThreeLine || subtitle != null), super(key: key); /// A widget to display before the title. diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index b925a28d0e..8ffb1a62dc 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -17,7 +17,7 @@ abstract class MergeableMaterialItem { /// const constructors so that they can be used in const expressions. /// /// The argument is the [key], which must not be null. - const MergeableMaterialItem(this.key); + const MergeableMaterialItem(this.key) : assert(key != null); /// The key for this item of the list. /// diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index 968e973aa2..5b901b0b2a 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart @@ -232,7 +232,8 @@ class DefaultTabController extends StatefulWidget { @required this.length, this.initialIndex: 0, @required this.child, - }) : super(key: key); + }) : assert(initialIndex != null), + super(key: key); /// The total number of tabs. Must be greater than one. final int length; diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 9c39e5483c..e49250724f 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -993,7 +993,7 @@ class LinearGradient extends Gradient { /// * [CustomPainter], which shows how to use the above sample code in a custom /// painter. class RadialGradient extends Gradient { - /// Creates a radial graident. + /// Creates a radial gradient. /// /// The [colors] argument must not be null. If [stops] is non-null, it must /// have the same length as [colors]. @@ -1003,7 +1003,10 @@ class RadialGradient extends Gradient { this.colors, this.stops, this.tileMode: TileMode.clamp, - }); + }) : assert(center != null), + assert(radius != null), + assert(colors != null), + assert(tileMode != null); /// The center of the gradient, as an offset into the unit square /// describing the gradient which will be mapped onto the paint box. @@ -1265,7 +1268,7 @@ class DecorationImage { this.centerSlice, this.colorFilter, this.alignment, - }); + }) : assert(image != null); /// The image to be painted into the decoration. final ImageProvider image; diff --git a/packages/flutter/lib/src/painting/colors.dart b/packages/flutter/lib/src/painting/colors.dart index 5d0bfdad7c..a12acd5138 100644 --- a/packages/flutter/lib/src/painting/colors.dart +++ b/packages/flutter/lib/src/painting/colors.dart @@ -17,7 +17,11 @@ class HSVColor { /// /// All the arguments must not be null and be in their respective ranges. See /// the fields for each parameter for a description of their ranges. - const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value); + const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value) + : assert(alpha != null), + assert(hue != null), + assert(saturation != null), + assert(value != null); /// Alpha, from 0.0 to 1.0. final double alpha; diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 5083b01b2a..88c27fca1e 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -26,7 +26,7 @@ class TextStyle { this.decoration, this.decorationColor, this.decorationStyle - }); + }) : assert(inherit != null); /// Whether null values are replaced with their value in an ancestor text style (e.g., in a [TextSpan] tree). final bool inherit;