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