Commit 60f5ae8e authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Add const non-null asserts where required (#9945)

Also includes minor doc fixes.
parent 0b2fb132
...@@ -349,10 +349,10 @@ class UserHeader extends StatelessWidget { ...@@ -349,10 +349,10 @@ class UserHeader extends StatelessWidget {
child: new Row( child: new Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new Padding( const Padding(
padding: const EdgeInsets.only(right: 8.0), padding: const EdgeInsets.only(right: 8.0),
child: new Image( child: const Image(
image: new AssetImage('packages/flutter_gallery_assets/ali_connors_sml.png'), image: const AssetImage('packages/flutter_gallery_assets/ali_connors_sml.png'),
width: 32.0, width: 32.0,
height: 32.0 height: 32.0
) )
...@@ -407,10 +407,10 @@ class ItemImageBox extends StatelessWidget { ...@@ -407,10 +407,10 @@ class ItemImageBox extends StatelessWidget {
children: <Widget>[ children: <Widget>[
new Stack( new Stack(
children: <Widget>[ children: <Widget>[
new SizedBox( const SizedBox(
height: 230.0, height: 230.0,
child: new Image( child: const Image(
image: new AssetImage('packages/flutter_gallery_assets/top_10_australian_beaches.png') image: const AssetImage('packages/flutter_gallery_assets/top_10_australian_beaches.png')
) )
), ),
new Theme( new Theme(
......
...@@ -93,10 +93,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -93,10 +93,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
new UserAccountsDrawerHeader( new UserAccountsDrawerHeader(
accountName: const Text('Zach Widget'), accountName: const Text('Zach Widget'),
accountEmail: const Text('zach.widget@example.com'), accountEmail: const Text('zach.widget@example.com'),
currentAccountPicture: new CircleAvatar(backgroundImage: new AssetImage(_kAsset0)), currentAccountPicture: const CircleAvatar(backgroundImage: const AssetImage(_kAsset0)),
otherAccountsPictures: <Widget>[ otherAccountsPictures: const <Widget>[
new CircleAvatar(backgroundImage: new AssetImage(_kAsset1)), const CircleAvatar(backgroundImage: const AssetImage(_kAsset1)),
new CircleAvatar(backgroundImage: new AssetImage(_kAsset2)), const CircleAvatar(backgroundImage: const AssetImage(_kAsset2)),
], ],
onDetailsPressed: () { onDetailsPressed: () {
_showDrawerContents = !_showDrawerContents; _showDrawerContents = !_showDrawerContents;
...@@ -164,10 +164,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -164,10 +164,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
new Container( new Container(
width: 100.0, width: 100.0,
height: 100.0, height: 100.0,
decoration: new BoxDecoration( decoration: const BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
image: new DecorationImage( image: const DecorationImage(
image: new AssetImage(_kAsset0), image: const AssetImage(_kAsset0),
), ),
), ),
), ),
......
...@@ -33,7 +33,7 @@ class FlutterErrorDetails { ...@@ -33,7 +33,7 @@ class FlutterErrorDetails {
this.stackFilter, this.stackFilter,
this.informationCollector, this.informationCollector,
this.silent: false this.silent: false
}) : assert(exception != null); });
/// The exception. Often this will be an [AssertionError], maybe specifically /// The exception. Often this will be an [AssertionError], maybe specifically
/// a [FlutterError]. However, this could be any value at all. /// a [FlutterError]. However, this could be any value at all.
......
...@@ -504,7 +504,9 @@ class BoxHitTestEntry extends HitTestEntry { ...@@ -504,7 +504,9 @@ class BoxHitTestEntry extends HitTestEntry {
/// Creates a box hit test entry. /// Creates a box hit test entry.
/// ///
/// The [localPosition] argument must not be null. /// The [localPosition] argument must not be null.
const BoxHitTestEntry(RenderBox target, this.localPosition) : super(target); const BoxHitTestEntry(RenderBox target, this.localPosition)
: assert(localPosition != null),
super(target);
@override @override
RenderBox get target => super.target; RenderBox get target => super.target;
......
...@@ -229,6 +229,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -229,6 +229,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
TextBaseline get textBaseline => _textBaseline; TextBaseline get textBaseline => _textBaseline;
TextBaseline _textBaseline; TextBaseline _textBaseline;
set textBaseline(TextBaseline value) { set textBaseline(TextBaseline value) {
assert(_crossAxisAlignment != CrossAxisAlignment.baseline || value != null);
if (_textBaseline != value) { if (_textBaseline != value) {
_textBaseline = value; _textBaseline = value;
markNeedsLayout(); markNeedsLayout();
......
...@@ -2627,7 +2627,8 @@ class RenderSemanticsGestureHandler extends RenderProxyBox implements SemanticsA ...@@ -2627,7 +2627,8 @@ class RenderSemanticsGestureHandler extends RenderProxyBox implements SemanticsA
GestureDragUpdateCallback onHorizontalDragUpdate, GestureDragUpdateCallback onHorizontalDragUpdate,
GestureDragUpdateCallback onVerticalDragUpdate, GestureDragUpdateCallback onVerticalDragUpdate,
this.scrollFactor: 0.8 this.scrollFactor: 0.8
}) : _onTap = onTap, }) : assert(scrollFactor != null),
_onTap = onTap,
_onLongPress = onLongPress, _onLongPress = onLongPress,
_onHorizontalDragUpdate = onHorizontalDragUpdate, _onHorizontalDragUpdate = onHorizontalDragUpdate,
_onVerticalDragUpdate = onVerticalDragUpdate, _onVerticalDragUpdate = onVerticalDragUpdate,
......
...@@ -189,7 +189,14 @@ class SliverConstraints extends Constraints { ...@@ -189,7 +189,14 @@ class SliverConstraints extends Constraints {
@required this.remainingPaintExtent, @required this.remainingPaintExtent,
@required this.crossAxisExtent, @required this.crossAxisExtent,
@required this.viewportMainAxisExtent, @required this.viewportMainAxisExtent,
}); }) : assert(axisDirection != null),
assert(growthDirection != null),
assert(userScrollDirection != null),
assert(scrollOffset != null),
assert(overlap != null),
assert(remainingPaintExtent != null),
assert(crossAxisExtent != null),
assert(viewportMainAxisExtent != null);
/// Creates a copy of this object but with the given fields replaced with the /// Creates a copy of this object but with the given fields replaced with the
/// new values. /// new values.
...@@ -469,7 +476,13 @@ class SliverGeometry { ...@@ -469,7 +476,13 @@ class SliverGeometry {
bool visible, bool visible,
this.hasVisualOverflow: false, this.hasVisualOverflow: false,
this.scrollOffsetCorrection: 0.0 this.scrollOffsetCorrection: 0.0
}) : layoutExtent = layoutExtent ?? paintExtent, }) : assert(scrollExtent != null),
assert(paintExtent != null),
assert(paintOrigin != null),
assert(maxPaintExtent != null),
assert(hasVisualOverflow != null),
assert(scrollOffsetCorrection != null),
layoutExtent = layoutExtent ?? paintExtent,
hitTestExtent = hitTestExtent ?? paintExtent, hitTestExtent = hitTestExtent ?? paintExtent,
visible = visible ?? paintExtent > 0.0; visible = visible ?? paintExtent > 0.0;
...@@ -635,7 +648,9 @@ class SliverHitTestEntry extends HitTestEntry { ...@@ -635,7 +648,9 @@ class SliverHitTestEntry extends HitTestEntry {
const SliverHitTestEntry(RenderSliver target, { const SliverHitTestEntry(RenderSliver target, {
@required this.mainAxisPosition, @required this.mainAxisPosition,
@required this.crossAxisPosition, @required this.crossAxisPosition,
}) : super(target); }) : assert(mainAxisPosition != null),
assert(crossAxisPosition != null),
super(target);
@override @override
RenderSliver get target => super.target; RenderSliver get target => super.target;
......
...@@ -151,7 +151,11 @@ class SliverGridRegularTileLayout extends SliverGridLayout { ...@@ -151,7 +151,11 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
@required this.crossAxisStride, @required this.crossAxisStride,
@required this.childMainAxisExtent, @required this.childMainAxisExtent,
@required this.childCrossAxisExtent, @required this.childCrossAxisExtent,
}); }) : assert(crossAxisCount != null && crossAxisCount > 0),
assert(mainAxisStride != null && mainAxisStride >= 0),
assert(crossAxisStride != null && crossAxisStride >= 0),
assert(childMainAxisExtent != null && childMainAxisExtent >= 0),
assert(childCrossAxisExtent != null && childCrossAxisExtent >= 0);
/// The number of children in the cross axis. /// The number of children in the cross axis.
final int crossAxisCount; final int crossAxisCount;
...@@ -272,7 +276,10 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate { ...@@ -272,7 +276,10 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate {
this.mainAxisSpacing: 0.0, this.mainAxisSpacing: 0.0,
this.crossAxisSpacing: 0.0, this.crossAxisSpacing: 0.0,
this.childAspectRatio: 1.0, this.childAspectRatio: 1.0,
}); }) : assert(crossAxisCount != null && crossAxisCount > 0),
assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0),
assert(childAspectRatio != null && childAspectRatio > 0);
/// The number of children in the cross axis. /// The number of children in the cross axis.
final int crossAxisCount; final int crossAxisCount;
...@@ -347,15 +354,18 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate { ...@@ -347,15 +354,18 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate {
/// Creates a delegate that makes grid layouts with tiles that have a maximum /// Creates a delegate that makes grid layouts with tiles that have a maximum
/// cross-axis extent. /// cross-axis extent.
/// ///
/// All of the arguments must not be null. The `maxCrossAxisExtent` and /// All of the arguments must not be null. The [maxCrossAxisExtent] and
/// `crossAxisSpacing` arguments must not be negative. The `crossAxisCount` /// [mainAxisSpacing], and [crossAxisSpacing] arguments must not be negative.
/// and `childAspectRatio` arguments must be greater than zero. /// The [childAspectRatio] argument must be greater than zero.
const SliverGridDelegateWithMaxCrossAxisExtent({ const SliverGridDelegateWithMaxCrossAxisExtent({
@required this.maxCrossAxisExtent, @required this.maxCrossAxisExtent,
this.mainAxisSpacing: 0.0, this.mainAxisSpacing: 0.0,
this.crossAxisSpacing: 0.0, this.crossAxisSpacing: 0.0,
this.childAspectRatio: 1.0, this.childAspectRatio: 1.0,
}); }) : assert(maxCrossAxisExtent != null && maxCrossAxisExtent >= 0),
assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0),
assert(childAspectRatio != null && childAspectRatio > 0);
/// The maximum extent of tiles in the cross axis. /// The maximum extent of tiles in the cross axis.
/// ///
......
...@@ -121,7 +121,7 @@ class FixedColumnWidth extends TableColumnWidth { ...@@ -121,7 +121,7 @@ class FixedColumnWidth extends TableColumnWidth {
/// Creates a column width based on a fixed number of logical pixels. /// Creates a column width based on a fixed number of logical pixels.
/// ///
/// The [value] argument must not be null. /// The [value] argument must not be null.
const FixedColumnWidth(this.value); const FixedColumnWidth(this.value) : assert(value != null);
/// The width the column should occupy in logical pixels. /// The width the column should occupy in logical pixels.
final double value; final double value;
...@@ -148,7 +148,7 @@ class FractionColumnWidth extends TableColumnWidth { ...@@ -148,7 +148,7 @@ class FractionColumnWidth extends TableColumnWidth {
/// maxWidth. /// maxWidth.
/// ///
/// The [value] argument must not be null. /// The [value] argument must not be null.
const FractionColumnWidth(this.value); const FractionColumnWidth(this.value) : assert(value != null);
/// The fraction of the table's constraints' maxWidth that this column should /// The fraction of the table's constraints' maxWidth that this column should
/// occupy. /// occupy.
...@@ -184,7 +184,7 @@ class FlexColumnWidth extends TableColumnWidth { ...@@ -184,7 +184,7 @@ class FlexColumnWidth extends TableColumnWidth {
/// the other columns have been laid out. /// the other columns have been laid out.
/// ///
/// The [value] argument must not be null. /// The [value] argument must not be null.
const FlexColumnWidth([this.value = 1.0]); const FlexColumnWidth([this.value = 1.0]) : assert(value != null);
/// The reaction of the of the remaining space once all the other columns have /// The reaction of the of the remaining space once all the other columns have
/// been laid out that this column should occupy. /// been laid out that this column should occupy.
......
...@@ -223,7 +223,9 @@ class AssetBundleImageKey { ...@@ -223,7 +223,9 @@ class AssetBundleImageKey {
@required this.bundle, @required this.bundle,
@required this.name, @required this.name,
@required this.scale @required this.scale
}); }) : assert(bundle != null),
assert(name != null),
assert(scale != null);
/// The bundle from which the image will be obtained. /// The bundle from which the image will be obtained.
/// ///
...@@ -312,7 +314,9 @@ class NetworkImage extends ImageProvider<NetworkImage> { ...@@ -312,7 +314,9 @@ class NetworkImage extends ImageProvider<NetworkImage> {
/// Creates an object that fetches the image at the given URL. /// Creates an object that fetches the image at the given URL.
/// ///
/// The arguments must not be null. /// The arguments must not be null.
const NetworkImage(this.url, { this.scale: 1.0 }) : assert(url != null); const NetworkImage(this.url, { this.scale: 1.0 })
: assert(url != null),
assert(scale != null);
/// The URL from which the image will be fetched. /// The URL from which the image will be fetched.
final String url; final String url;
...@@ -382,7 +386,9 @@ class FileImage extends ImageProvider<FileImage> { ...@@ -382,7 +386,9 @@ class FileImage extends ImageProvider<FileImage> {
/// Creates an object that decodes a [File] as an image. /// Creates an object that decodes a [File] as an image.
/// ///
/// The arguments must not be null. /// The arguments must not be null.
const FileImage(this.file, { this.scale: 1.0 }); const FileImage(this.file, { this.scale: 1.0 })
: assert(file != null),
assert(scale != null);
/// The file to decode into an image. /// The file to decode into an image.
final File file; final File file;
...@@ -444,7 +450,9 @@ class MemoryImage extends ImageProvider<MemoryImage> { ...@@ -444,7 +450,9 @@ class MemoryImage extends ImageProvider<MemoryImage> {
/// Creates an object that decodes a [Uint8List] buffer as an image. /// Creates an object that decodes a [Uint8List] buffer as an image.
/// ///
/// The arguments must not be null. /// The arguments must not be null.
const MemoryImage(this.bytes, { this.scale: 1.0 }); const MemoryImage(this.bytes, { this.scale: 1.0 })
: assert(bytes != null),
assert(scale != null);
/// The bytes to decode into an image. /// The bytes to decode into an image.
final Uint8List bytes; final Uint8List bytes;
...@@ -504,13 +512,11 @@ class ExactAssetImage extends AssetBundleImageProvider { ...@@ -504,13 +512,11 @@ class ExactAssetImage extends AssetBundleImageProvider {
/// defaults to 1.0. The [bundle] argument may be null, in which case the /// defaults to 1.0. The [bundle] argument may be null, in which case the
/// bundle provided in the [ImageConfiguration] passed to the [resolve] call /// bundle provided in the [ImageConfiguration] passed to the [resolve] call
/// will be used instead. /// will be used instead.
ExactAssetImage(this.name, { const ExactAssetImage(this.name, {
this.scale: 1.0, this.scale: 1.0,
this.bundle this.bundle
}) { }) : assert(name != null),
assert(name != null); assert(scale != null);
assert(scale != null);
}
/// The key to use to obtain the resource from the [bundle]. This is the /// The key to use to obtain the resource from the [bundle]. This is the
/// argument passed to [AssetBundle.load]. /// argument passed to [AssetBundle.load].
......
...@@ -60,11 +60,7 @@ class AssetImage extends AssetBundleImageProvider { ...@@ -60,11 +60,7 @@ class AssetImage extends AssetBundleImageProvider {
/// ///
/// The [name] argument must not be null. It should name the main asset from /// The [name] argument must not be null. It should name the main asset from
/// the set of images to chose from. /// the set of images to chose from.
AssetImage(this.name, { const AssetImage(this.name, { this.bundle }) : assert(name != null);
this.bundle
}) {
assert(name != null);
}
/// The name of the main asset from the set of images to chose from. See the /// The name of the main asset from the set of images to chose from. See the
/// documentation for the [AssetImage] class itself for details. /// documentation for the [AssetImage] class itself for details.
......
...@@ -16,10 +16,9 @@ class ImageInfo { ...@@ -16,10 +16,9 @@ class ImageInfo {
/// Creates an [ImageInfo] object for the given image and scale. /// Creates an [ImageInfo] object for the given image and scale.
/// ///
/// Both the image and the scale must not be null. /// Both the image and the scale must not be null.
ImageInfo({ @required this.image, this.scale: 1.0 }) { const ImageInfo({ @required this.image, this.scale: 1.0 })
assert(image != null); : assert(image != null),
assert(scale != null); assert(scale != null);
}
/// The raw image pixels. /// The raw image pixels.
/// ///
......
...@@ -42,7 +42,11 @@ class RawKeyEventDataAndroid extends RawKeyEventData { ...@@ -42,7 +42,11 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
this.keyCode: 0, this.keyCode: 0,
this.scanCode: 0, this.scanCode: 0,
this.metaState: 0, this.metaState: 0,
}); }) : assert(flags != null),
assert(codePoint != null),
assert(keyCode != null),
assert(scanCode != null),
assert(metaState != null);
/// See <https://developer.android.com/reference/android/view/KeyEvent.html#getFlags()> /// See <https://developer.android.com/reference/android/view/KeyEvent.html#getFlags()>
final int flags; final int flags;
...@@ -67,12 +71,14 @@ class RawKeyEventDataAndroid extends RawKeyEventData { ...@@ -67,12 +71,14 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
class RawKeyEventDataFuchsia extends RawKeyEventData { class RawKeyEventDataFuchsia extends RawKeyEventData {
/// Creates a key event data structure specific for Android. /// Creates a key event data structure specific for Android.
/// ///
/// The [hidUsage] and [codePoint] arguments must not be null. /// The [hidUsage], [codePoint], and [modifiers] arguments must not be null.
const RawKeyEventDataFuchsia({ const RawKeyEventDataFuchsia({
this.hidUsage: 0, this.hidUsage: 0,
this.codePoint: 0, this.codePoint: 0,
this.modifiers: 0, this.modifiers: 0,
}); }) : assert(hidUsage != null),
assert(codePoint != null),
assert(modifiers != null);
/// The USB HID usage. /// The USB HID usage.
/// ///
...@@ -84,7 +90,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData { ...@@ -84,7 +90,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData {
/// If there is no Unicode code point, this value is zero. /// If there is no Unicode code point, this value is zero.
final int codePoint; final int codePoint;
/// The modifiers that we present when the key event occured. /// The modifiers that we present when the key event occurred.
/// ///
/// See <https://fuchsia.googlesource.com/mozart/+/master/services/input/input_event_constants.fidl> /// See <https://fuchsia.googlesource.com/mozart/+/master/services/input/input_event_constants.fidl>
/// for the numerical values of the modifiers. /// for the numerical values of the modifiers.
......
...@@ -21,11 +21,15 @@ class TextRange { ...@@ -21,11 +21,15 @@ class TextRange {
const TextRange({ const TextRange({
@required this.start, @required this.start,
@required this.end @required this.end
}); }) : assert(start != null && start >= -1),
assert(end != null && end >= -1);
/// A text range that starts and ends at offset. /// A text range that starts and ends at offset.
///
/// The [offset] argument must be non-null and greater than or equal to -1.
const TextRange.collapsed(int offset) const TextRange.collapsed(int offset)
: start = offset, : assert(offset != null && offset >= -1),
start = offset,
end = offset; end = offset;
/// A text range that contains nothing and is not in the text. /// A text range that contains nothing and is not in the text.
......
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