From 2e7d6fa7baf2a5dac99f1a939dc031f885f241c9 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 25 Jan 2023 10:15:02 -0800 Subject: [PATCH] Remove unnecessary null checks (#39113) --- analysis_options.yaml | 2 - ci/licenses_golden/tool_signature | 2 +- lib/ui/compositing.dart | 9 - lib/ui/experiments/scene.dart | 4 +- lib/ui/geometry.dart | 29 +-- lib/ui/hooks.dart | 12 -- lib/ui/isolate_name_server.dart | 4 - lib/ui/painting.dart | 175 +++--------------- lib/ui/platform_dispatcher.dart | 6 +- lib/ui/plugins.dart | 5 +- lib/ui/pointer.dart | 2 +- lib/ui/semantics.dart | 10 +- lib/ui/text.dart | 22 +-- lib/web_ui/lib/geometry.dart | 29 +-- lib/web_ui/lib/painting.dart | 13 +- lib/web_ui/lib/path_metrics.dart | 4 +- lib/web_ui/lib/platform_dispatcher.dart | 6 +- lib/web_ui/lib/pointer.dart | 3 +- lib/web_ui/lib/semantics.dart | 4 +- lib/web_ui/lib/src/engine/canvas_pool.dart | 5 +- .../engine/canvaskit/canvaskit_canvas.dart | 48 ----- .../lib/src/engine/canvaskit/layer.dart | 1 - .../engine/canvaskit/layer_scene_builder.dart | 2 - lib/web_ui/lib/src/engine/canvaskit/path.dart | 1 - .../lib/src/engine/canvaskit/shader.dart | 6 - .../lib/src/engine/canvaskit/surface.dart | 4 +- .../lib/src/engine/canvaskit/vertices.dart | 4 - .../lib/src/engine/html/bitmap_canvas.dart | 6 +- lib/web_ui/lib/src/engine/html/canvas.dart | 47 ----- .../lib/src/engine/html/dom_canvas.dart | 7 +- lib/web_ui/lib/src/engine/html/painting.dart | 6 +- lib/web_ui/lib/src/engine/html/picture.dart | 3 +- .../lib/src/engine/html/render_vertices.dart | 10 +- .../lib/src/engine/html/scene_builder.dart | 5 - .../src/engine/html/shaders/image_shader.dart | 1 - .../lib/src/engine/html/shaders/shader.dart | 7 - lib/web_ui/lib/src/engine/html/surface.dart | 3 - .../lib/src/engine/html/surface_stats.dart | 1 - lib/web_ui/lib/src/engine/initialization.dart | 1 - .../lib/src/engine/navigation/history.dart | 2 - .../lib/src/engine/pointer_binding.dart | 6 - .../lib/src/engine/pointer_converter.dart | 1 - .../lib/src/engine/semantics/semantics.dart | 16 +- .../lib/src/engine/services/buffers.dart | 2 - .../src/engine/services/message_codec.dart | 4 +- .../src/engine/services/message_codecs.dart | 1 - .../src/engine/services/serialization.dart | 2 +- lib/web_ui/lib/src/engine/text/paragraph.dart | 2 - .../src/engine/text_editing/text_editing.dart | 1 - lib/web_ui/lib/src/engine/validators.dart | 5 - lib/web_ui/lib/text.dart | 14 +- lib/web_ui/lib/window.dart | 3 +- testing/dart/color_filter_test.dart | 2 - testing/dart/color_test.dart | 20 +- testing/dart/compositing_test.dart | 1 - testing/dart/mask_filter_test.dart | 1 - testing/scenario_app/lib/main.dart | 1 - .../lib/src/animated_color_square.dart | 7 +- .../scenario_app/lib/src/bogus_font_text.dart | 3 +- .../lib/src/initial_route_reply.dart | 3 +- .../lib/src/locale_initialization.dart | 3 +- .../scenario_app/lib/src/platform_view.dart | 40 ++-- .../scenario_app/lib/src/poppable_screen.dart | 3 +- tools/licenses/lib/licenses.dart | 4 +- tools/licenses/lib/main.dart | 14 +- web_sdk/sdk_rewriter.dart | 2 +- 66 files changed, 109 insertions(+), 563 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index de29de16689b8..40329d6e205a2 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -12,8 +12,6 @@ analyzer: # allow self-reference to deprecated members (we do this because otherwise we have # to annotate every member in every test, assert, etc, when we deprecate something) deprecated_member_use_from_same_package: ignore - # Turned off until null-safe rollout is complete. - unnecessary_null_comparison: ignore exclude: # DIFFERENT FROM FLUTTER/FLUTTER # Fixture depends on dart:ui and raises false positives. - flutter_frontend_server/test/fixtures/lib/main.dart diff --git a/ci/licenses_golden/tool_signature b/ci/licenses_golden/tool_signature index 4a29044da412a..55e23e24539b1 100644 --- a/ci/licenses_golden/tool_signature +++ b/ci/licenses_golden/tool_signature @@ -1,2 +1,2 @@ -Signature: 974dd21be7c0e97f436f3758b6de4cee +Signature: ccf8317fb6539998c8f4ff0a96d7f698 diff --git a/lib/ui/compositing.dart b/lib/ui/compositing.dart index a55480c028e79..f20ecff7349c6 100644 --- a/lib/ui/compositing.dart +++ b/lib/ui/compositing.dart @@ -375,7 +375,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 { Clip clipBehavior = Clip.antiAlias, ClipRectEngineLayer? oldLayer, }) { - assert(clipBehavior != null); assert(clipBehavior != Clip.none); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRect')); final EngineLayer engineLayer = EngineLayer._(); @@ -411,7 +410,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 { Clip clipBehavior = Clip.antiAlias, ClipRRectEngineLayer? oldLayer, }) { - assert(clipBehavior != null); assert(clipBehavior != Clip.none); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRRect')); final EngineLayer engineLayer = EngineLayer._(); @@ -439,7 +437,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 { Clip clipBehavior = Clip.antiAlias, ClipPathEngineLayer? oldLayer, }) { - assert(clipBehavior != null); assert(clipBehavior != Clip.none); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipPath')); final EngineLayer engineLayer = EngineLayer._(); @@ -494,10 +491,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 { ColorFilter filter, { ColorFilterEngineLayer? oldLayer, }) { - assert(filter != null); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushColorFilter')); final _ColorFilter nativeFilter = filter._toNativeColorFilter()!; - assert(nativeFilter != null); final EngineLayer engineLayer = EngineLayer._(); _pushColorFilter(engineLayer, nativeFilter, oldLayer?._nativeLayer); final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(engineLayer); @@ -523,10 +518,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 { Offset offset = Offset.zero, ImageFilterEngineLayer? oldLayer, }) { - assert(filter != null); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushImageFilter')); final _ImageFilter nativeFilter = filter._toNativeImageFilter(); - assert(nativeFilter != null); final EngineLayer engineLayer = EngineLayer._(); _pushImageFilter(engineLayer, nativeFilter, offset.dx, offset.dy, oldLayer?._nativeLayer); final ImageFilterEngineLayer layer = ImageFilterEngineLayer._(engineLayer); @@ -799,7 +792,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 { bool freeze = false, FilterQuality filterQuality = FilterQuality.low, }) { - assert(offset != null, 'Offset argument was null'); _addTexture(offset.dx, offset.dy, width, height, textureId, freeze, filterQuality.index); } @@ -828,7 +820,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 { double width = 0.0, double height = 0.0, }) { - assert(offset != null, 'Offset argument was null'); _addPlatformView(offset.dx, offset.dy, width, height, viewId); } diff --git a/lib/ui/experiments/scene.dart b/lib/ui/experiments/scene.dart index 3f2b2422daf45..c452cf46d0266 100644 --- a/lib/ui/experiments/scene.dart +++ b/lib/ui/experiments/scene.dart @@ -80,9 +80,7 @@ class SceneNode extends NativeFieldWrapperClass1 { >{}; static Future _reinitializeScene(String assetKey) async { - final WeakReference? sceneRef = _ipsceneRegistry == null - ? null - : _ipsceneRegistry[assetKey]; + final WeakReference? sceneRef = _ipsceneRegistry[assetKey]; // If a scene for the asset isn't already registered, then there's no // need to reinitialize it. diff --git a/lib/ui/geometry.dart b/lib/ui/geometry.dart index 25078b56602e7..26ac53a5f4df6 100644 --- a/lib/ui/geometry.dart +++ b/lib/ui/geometry.dart @@ -12,9 +12,7 @@ abstract class OffsetBase { /// /// The first argument sets the horizontal component, and the second the /// vertical component. - const OffsetBase(this._dx, this._dy) - : assert(_dx != null), - assert(_dy != null); + const OffsetBase(this._dx, this._dy); final double _dx; final double _dy; @@ -314,7 +312,6 @@ class Offset extends OffsetBase { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static Offset? lerp(Offset? a, Offset? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -590,7 +587,6 @@ class Size extends OffsetBase { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static Size? lerp(Size? a, Size? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -637,11 +633,7 @@ class Rect { /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb.png#gh-light-mode-only) /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb_dark.png#gh-dark-mode-only) @pragma('vm:entry-point') - const Rect.fromLTRB(this.left, this.top, this.right, this.bottom) - : assert(left != null), - assert(top != null), - assert(right != null), - assert(bottom != null); + const Rect.fromLTRB(this.left, this.top, this.right, this.bottom); /// Construct a rectangle from its left and top edges, its width, and its /// height. @@ -891,7 +883,6 @@ class Rect { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static Rect? lerp(Rect? a, Rect? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -1059,7 +1050,6 @@ class Radius { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static Radius? lerp(Radius? a, Radius? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -1268,19 +1258,7 @@ class RRect { this.brRadiusY = 0.0, this.blRadiusX = 0.0, this.blRadiusY = 0.0, - }) : assert(left != null), - assert(top != null), - assert(right != null), - assert(bottom != null), - assert(tlRadiusX != null), - assert(tlRadiusY != null), - assert(trRadiusX != null), - assert(trRadiusY != null), - assert(brRadiusX != null), - assert(brRadiusY != null), - assert(blRadiusX != null), - assert(blRadiusY != null), - assert(tlRadiusX >= 0), + }) : assert(tlRadiusX >= 0), assert(tlRadiusY >= 0), assert(trRadiusX >= 0), assert(trRadiusY >= 0), @@ -1661,7 +1639,6 @@ class RRect { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static RRect? lerp(RRect? a, RRect? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index 38375989e96a1..0ac4fe49922b7 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -138,9 +138,6 @@ void _invoke(void Function()? callback, Zone zone) { if (callback == null) { return; } - - assert(zone != null); - if (identical(zone, Zone.current)) { callback(); } else { @@ -157,9 +154,6 @@ void _invoke1(void Function(A a)? callback, Zone zone, A arg) { if (callback == null) { return; } - - assert(zone != null); - if (identical(zone, Zone.current)) { callback(arg); } else { @@ -176,9 +170,6 @@ void _invoke2(void Function(A1 a1, A2 a2)? callback, Zone zone, A1 arg1, if (callback == null) { return; } - - assert(zone != null); - if (identical(zone, Zone.current)) { callback(arg1, arg2); } else { @@ -197,9 +188,6 @@ void _invoke3(void Function(A1 a1, A2 a2, A3 a3)? callback, Zone zon if (callback == null) { return; } - - assert(zone != null); - if (identical(zone, Zone.current)) { callback(arg1, arg2, arg3); } else { diff --git a/lib/ui/isolate_name_server.dart b/lib/ui/isolate_name_server.dart index d2b2f29ccf3c1..ba3d53dab64a5 100644 --- a/lib/ui/isolate_name_server.dart +++ b/lib/ui/isolate_name_server.dart @@ -31,7 +31,6 @@ class IsolateNameServer { /// /// The `name` argument must not be null. static SendPort? lookupPortByName(String name) { - assert(name != null, "'name' cannot be null."); return _lookupPortByName(name); } @@ -49,8 +48,6 @@ class IsolateNameServer { /// /// The `port` and `name` arguments must not be null. static bool registerPortWithName(SendPort port, String name) { - assert(port != null, "'port' cannot be null."); - assert(name != null, "'name' cannot be null."); return _registerPortWithName(port, name); } @@ -66,7 +63,6 @@ class IsolateNameServer { /// /// The `name` argument must not be null. static bool removePortNameMapping(String name) { - assert(name != null, "'name' cannot be null."); return _removePortNameMapping(name); } diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 51ae64542fbdb..51bd467893ee2 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -23,32 +23,27 @@ part of dart.ui; // which can not be rendered by Skia. bool _rectIsValid(Rect rect) { - assert(rect != null, 'Rect argument was null.'); assert(!rect.hasNaN, 'Rect argument contained a NaN value.'); return true; } bool _rrectIsValid(RRect rrect) { - assert(rrect != null, 'RRect argument was null.'); assert(!rrect.hasNaN, 'RRect argument contained a NaN value.'); return true; } bool _offsetIsValid(Offset offset) { - assert(offset != null, 'Offset argument was null.'); assert(!offset.dx.isNaN && !offset.dy.isNaN, 'Offset argument contained a NaN value.'); return true; } bool _matrix4IsValid(Float64List matrix4) { - assert(matrix4 != null, 'Matrix4 argument was null.'); assert(matrix4.length == 16, 'Matrix4 must have 16 entries.'); assert(matrix4.every((double value) => value.isFinite), 'Matrix4 entries must be finite.'); return true; } bool _radiusIsValid(Radius radius) { - assert(radius != null, 'Radius argument was null.'); assert(!radius.x.isNaN && !radius.y.isNaN, 'Radius argument contained a NaN value.'); return true; } @@ -259,7 +254,6 @@ class Color { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static Color? lerp(Color? a, Color? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -319,7 +313,6 @@ class Color { /// /// The [opacity] value may not be null. static int getAlphaFromOpacity(double opacity) { - assert(opacity != null); return (clampDouble(opacity, 0.0, 1.0) * 255).round(); } @@ -1196,7 +1189,6 @@ class Paint { return Color(encoded ^ _kColorDefault); } set color(Color value) { - assert(value != null); final int encoded = value.value ^ _kColorDefault; _data.setInt32(_kColorOffset, encoded, _kFakeHostEndian); } @@ -1227,7 +1219,6 @@ class Paint { return BlendMode.values[encoded ^ _kBlendModeDefault]; } set blendMode(BlendMode value) { - assert(value != null); final int encoded = value.index ^ _kBlendModeDefault; _data.setInt32(_kBlendModeOffset, encoded, _kFakeHostEndian); } @@ -1239,7 +1230,6 @@ class Paint { return PaintingStyle.values[_data.getInt32(_kStyleOffset, _kFakeHostEndian)]; } set style(PaintingStyle value) { - assert(value != null); final int encoded = value.index; _data.setInt32(_kStyleOffset, encoded, _kFakeHostEndian); } @@ -1253,7 +1243,6 @@ class Paint { return _data.getFloat32(_kStrokeWidthOffset, _kFakeHostEndian); } set strokeWidth(double value) { - assert(value != null); final double encoded = value; _data.setFloat32(_kStrokeWidthOffset, encoded, _kFakeHostEndian); } @@ -1266,7 +1255,6 @@ class Paint { return StrokeCap.values[_data.getInt32(_kStrokeCapOffset, _kFakeHostEndian)]; } set strokeCap(StrokeCap value) { - assert(value != null); final int encoded = value.index; _data.setInt32(_kStrokeCapOffset, encoded, _kFakeHostEndian); } @@ -1300,7 +1288,6 @@ class Paint { return StrokeJoin.values[_data.getInt32(_kStrokeJoinOffset, _kFakeHostEndian)]; } set strokeJoin(StrokeJoin value) { - assert(value != null); final int encoded = value.index; _data.setInt32(_kStrokeJoinOffset, encoded, _kFakeHostEndian); } @@ -1338,7 +1325,6 @@ class Paint { return _data.getFloat32(_kStrokeMiterLimitOffset, _kFakeHostEndian); } set strokeMiterLimit(double value) { - assert(value != null); final double encoded = value - _kStrokeMiterLimitDefault; _data.setFloat32(_kStrokeMiterLimitOffset, encoded, _kFakeHostEndian); } @@ -1383,7 +1369,6 @@ class Paint { return FilterQuality.values[_data.getInt32(_kFilterQualityOffset, _kFakeHostEndian)]; } set filterQuality(FilterQuality value) { - assert(value != null); final int encoded = value.index; _data.setInt32(_kFilterQualityOffset, encoded, _kFakeHostEndian); } @@ -2753,7 +2738,6 @@ class Path extends NativeFieldWrapperClass1 { /// /// The `points` argument is interpreted as offsets from the origin. void addPolygon(List points, bool close) { - assert(points != null); _addPolygon(_encodePointList(points), close); } @@ -2777,7 +2761,6 @@ class Path extends NativeFieldWrapperClass1 { /// after the matrix is translated by the given offset. The matrix is a 4x4 /// matrix stored in column major order. void addPath(Path path, Offset offset, {Float64List? matrix4}) { - assert(path != null); // path is checked on the engine side assert(_offsetIsValid(offset)); if (matrix4 != null) { assert(_matrix4IsValid(matrix4)); @@ -2801,7 +2784,6 @@ class Path extends NativeFieldWrapperClass1 { /// after the matrix is translated by the given `offset`. The matrix is a 4x4 /// matrix stored in column major order. void extendWithPath(Path path, Offset offset, {Float64List? matrix4}) { - assert(path != null); // path is checked on the engine side assert(_offsetIsValid(offset)); if (matrix4 != null) { assert(_matrix4IsValid(matrix4)); @@ -2897,8 +2879,6 @@ class Path extends NativeFieldWrapperClass1 { /// curve order is reduced where possible so that cubics may be turned into /// quadratics, and quadratics maybe turned into lines. static Path combine(PathOperation operation, Path path1, Path path2) { - assert(path1 != null); - assert(path2 != null); final Path path = Path(); if (path._op(path1, path2, operation.index)) { return path; @@ -2953,9 +2933,7 @@ class Tangent { /// Creates a [Tangent] with the given values. /// /// The arguments must not be null. - const Tangent(this.position, this.vector) - : assert(position != null), - assert(vector != null); + const Tangent(this.position, this.vector); /// Creates a [Tangent] based on the angle rather than the vector. /// @@ -3021,7 +2999,7 @@ class PathMetrics extends collection.IterableBase { /// Used by [PathMetrics] to track iteration from one segment of a path to the /// next for measurement. class PathMetricIterator implements Iterator { - PathMetricIterator._(this._pathMeasure) : assert(_pathMeasure != null); + PathMetricIterator._(this._pathMeasure); PathMetric? _pathMetric; final _PathMeasure _pathMeasure; @@ -3065,8 +3043,7 @@ class PathMetricIterator implements Iterator { /// the path. class PathMetric { PathMetric._(this._measure) - : assert(_measure != null), - length = _measure.length(_measure.currentContourIndex), + : length = _measure.length(_measure.currentContourIndex), isClosed = _measure.isClosed(_measure.currentContourIndex), contourIndex = _measure.currentContourIndex; @@ -3252,8 +3229,7 @@ class MaskFilter { const MaskFilter.blur( this._style, this._sigma, - ) : assert(_style != null), - assert(_sigma != null); + ); final BlurStyle _style; final double _sigma; @@ -3472,28 +3448,24 @@ class ColorFilter implements ImageFilter { /// avoid repainting. class _ColorFilter extends NativeFieldWrapperClass1 { _ColorFilter.mode(this.creator) - : assert(creator != null), - assert(creator._type == ColorFilter._kTypeMode) { + : assert(creator._type == ColorFilter._kTypeMode) { _constructor(); _initMode(creator._color!.value, creator._blendMode!.index); } _ColorFilter.matrix(this.creator) - : assert(creator != null), - assert(creator._type == ColorFilter._kTypeMatrix) { + : assert(creator._type == ColorFilter._kTypeMatrix) { _constructor(); _initMatrix(Float32List.fromList(creator._matrix!)); } _ColorFilter.linearToSrgbGamma(this.creator) - : assert(creator != null), - assert(creator._type == ColorFilter._kTypeLinearToSrgbGamma) { + : assert(creator._type == ColorFilter._kTypeLinearToSrgbGamma) { _constructor(); _initLinearToSrgbGamma(); } _ColorFilter.srgbToLinearGamma(this.creator) - : assert(creator != null), - assert(creator._type == ColorFilter._kTypeSrgbToLinearGamma) { + : assert(creator._type == ColorFilter._kTypeSrgbToLinearGamma) { _constructor(); _initSrgbToLinearGamma(); } @@ -3531,25 +3503,18 @@ class _ColorFilter extends NativeFieldWrapperClass1 { abstract class ImageFilter { /// Creates an image filter that applies a Gaussian blur. factory ImageFilter.blur({ double sigmaX = 0.0, double sigmaY = 0.0, TileMode tileMode = TileMode.clamp }) { - assert(sigmaX != null); - assert(sigmaY != null); - assert(tileMode != null); return _GaussianBlurImageFilter(sigmaX: sigmaX, sigmaY: sigmaY, tileMode: tileMode); } /// Creates an image filter that dilates each input pixel's channel values /// to the max value within the given radii along the x and y axes. factory ImageFilter.dilate({ double radiusX = 0.0, double radiusY = 0.0 }) { - assert(radiusX != null); - assert(radiusY != null); return _DilateImageFilter(radiusX: radiusX, radiusY: radiusY); } /// Create a filter that erodes each input pixel's channel values /// to the minimum channel value within the given radii along the x and y axes. factory ImageFilter.erode({ double radiusX = 0.0, double radiusY = 0.0 }) { - assert(radiusX != null); - assert(radiusY != null); return _ErodeImageFilter(radiusX: radiusX, radiusY: radiusY); } @@ -3559,8 +3524,6 @@ abstract class ImageFilter { /// when used with [BackdropFilter] would magnify the background image. factory ImageFilter.matrix(Float64List matrix4, { FilterQuality filterQuality = FilterQuality.low }) { - assert(matrix4 != null); - assert(filterQuality != null); if (matrix4.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); } @@ -3573,7 +3536,6 @@ abstract class ImageFilter { /// subsequently applying `inner` and `outer`, i.e., /// result = outer(inner(source)). factory ImageFilter.compose({ required ImageFilter outer, required ImageFilter inner }) { - assert(inner != null && outer != null); return _ComposeImageFilter(innerFilter: inner, outerFilter: outer); } @@ -3758,8 +3720,7 @@ class _ComposeImageFilter implements ImageFilter { class _ImageFilter extends NativeFieldWrapperClass1 { /// Creates an image filter that applies a Gaussian blur. _ImageFilter.blur(_GaussianBlurImageFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { _constructor(); _initBlur(filter.sigmaX, filter.sigmaY, filter.tileMode.index); } @@ -3767,8 +3728,7 @@ class _ImageFilter extends NativeFieldWrapperClass1 { /// Creates an image filter that dilates each input pixel's channel values /// to the max value within the given radii along the x and y axes. _ImageFilter.dilate(_DilateImageFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { _constructor(); _initDilate(filter.radiusX, filter.radiusY); } @@ -3776,8 +3736,7 @@ class _ImageFilter extends NativeFieldWrapperClass1 { /// Create a filter that erodes each input pixel's channel values /// to the minimum channel value within the given radii along the x and y axes. _ImageFilter.erode(_ErodeImageFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { _constructor(); _initErode(filter.radiusX, filter.radiusY); } @@ -3787,8 +3746,7 @@ class _ImageFilter extends NativeFieldWrapperClass1 { /// For example, applying a positive scale matrix (see [Matrix4.diagonal3]) /// when used with [BackdropFilter] would magnify the background image. _ImageFilter.matrix(_MatrixImageFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { if (filter.data.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); } @@ -3798,8 +3756,7 @@ class _ImageFilter extends NativeFieldWrapperClass1 { /// Converts a color filter to an image filter. _ImageFilter.fromColorFilter(ColorFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { _constructor(); final _ColorFilter? nativeFilter = filter._toNativeColorFilter(); _initColorFilter(nativeFilter); @@ -3807,8 +3764,7 @@ class _ImageFilter extends NativeFieldWrapperClass1 { /// Composes `_innerFilter` with `_outerFilter`. _ImageFilter.composed(_ComposeImageFilter filter) - : assert(filter != null), - creator = filter { + : creator = filter { _constructor(); final _ImageFilter nativeFilterInner = filter.innerFilter._toNativeImageFilter(); final _ImageFilter nativeFilterOuter = filter.outerFilter._toNativeImageFilter(); @@ -3981,7 +3937,6 @@ Int32List _encodeColorList(List colors) { } Float32List _encodePointList(List points) { - assert(points != null); final int pointCount = points.length; final Float32List result = Float32List(pointCount * 2); for (int i = 0; i < pointCount; ++i) { @@ -4047,8 +4002,6 @@ class Gradient extends Shader { Float64List? matrix4, ]) : assert(_offsetIsValid(from)), assert(_offsetIsValid(to)), - assert(colors != null), - assert(tileMode != null), assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { _validateColorStops(colors, colorStops); @@ -4099,8 +4052,6 @@ class Gradient extends Shader { Offset? focal, double focalRadius = 0.0 ]) : assert(_offsetIsValid(center)), - assert(colors != null), - assert(tileMode != null), assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { _validateColorStops(colors, colorStops); @@ -4155,10 +4106,6 @@ class Gradient extends Shader { double endAngle = math.pi * 2, Float64List? matrix4, ]) : assert(_offsetIsValid(center)), - assert(colors != null), - assert(tileMode != null), - assert(startAngle != null), - assert(endAngle != null), assert(startAngle < endAngle), assert(matrix4 == null || _matrix4IsValid(matrix4)), super._() { @@ -4248,11 +4195,7 @@ class ImageShader extends Shader { ImageShader(Image image, TileMode tmx, TileMode tmy, Float64List matrix4, { FilterQuality? filterQuality, }) : - assert(image != null), // image is checked on the engine side assert(!image.debugDisposed), - assert(tmx != null), - assert(tmy != null), - assert(matrix4 != null), super._() { if (matrix4.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); @@ -4337,9 +4280,7 @@ class FragmentProgram extends NativeFieldWrapperClass1 { // If a shader for the asset isn't already registered, then there's no // need to reinitialize it. The new shader will be loaded and initialized // the next time the program access it. - final WeakReference? programRef = _shaderRegistry == null - ? null - : _shaderRegistry[assetKey]; + final WeakReference? programRef = _shaderRegistry[assetKey]; if (programRef == null) { return; } @@ -4588,8 +4529,7 @@ class Vertices extends NativeFieldWrapperClass1 { List? colors, List? textureCoordinates, List? indices, - }) : assert(mode != null), - assert(positions != null) { + }) { if (colors != null && colors.length != positions.length) { throw ArgumentError('"positions" and "colors" lengths must match.'); } @@ -4673,8 +4613,7 @@ class Vertices extends NativeFieldWrapperClass1 { Int32List? colors, Float32List? textureCoordinates, Uint16List? indices, - }) : assert(mode != null), - assert(positions != null) { + }) { if (positions.length % 2 != 0) { throw ArgumentError('"positions" must have an even number of entries (each coordinate is an x,y pair).'); } @@ -4813,7 +4752,7 @@ class Canvas extends NativeFieldWrapperClass1 { /// To end the recording, call [PictureRecorder.endRecording] on the /// given recorder. @pragma('vm:entry-point') - Canvas(PictureRecorder recorder, [ Rect? cullRect ]) : assert(recorder != null) { + Canvas(PictureRecorder recorder, [ Rect? cullRect ]) { if (recorder.isRecording) { throw ArgumentError('"recorder" must not already be associated with another Canvas.'); } @@ -4952,7 +4891,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// * [BlendMode], which discusses the use of [Paint.blendMode] with /// [saveLayer]. void saveLayer(Rect? bounds, Paint paint) { - assert(paint != null); if (bounds == null) { _saveLayerWithoutBounds(paint._objects, paint._data); } else { @@ -5028,7 +4966,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// Multiply the current transform by the specified 4⨉4 transformation matrix /// specified as a list of values in column-major order. void transform(Float64List matrix4) { - assert(matrix4 != null); if (matrix4.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); } @@ -5070,8 +5007,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// current clip. void clipRect(Rect rect, { ClipOp clipOp = ClipOp.intersect, bool doAntiAlias = true }) { assert(_rectIsValid(rect)); - assert(clipOp != null); - assert(doAntiAlias != null); _clipRect(rect.left, rect.top, rect.right, rect.bottom, clipOp.index, doAntiAlias); } @@ -5090,7 +5025,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// discussion of how to address that and some examples of using [clipRRect]. void clipRRect(RRect rrect, {bool doAntiAlias = true}) { assert(_rrectIsValid(rrect)); - assert(doAntiAlias != null); _clipRRect(rrect._getValue32(), doAntiAlias); } @@ -5108,8 +5042,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// in incorrect blending at the clip boundary. See [saveLayer] for a /// discussion of how to address that. void clipPath(Path path, {bool doAntiAlias = true}) { - assert(path != null); // path is checked on the engine side - assert(doAntiAlias != null); _clipPath(path, doAntiAlias); } @@ -5204,8 +5136,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// [BlendMode], with the given color being the source and the background /// being the destination. void drawColor(Color color, BlendMode blendMode) { - assert(color != null); - assert(blendMode != null); _drawColor(color.value, blendMode.index); } @@ -5222,7 +5152,6 @@ class Canvas extends NativeFieldWrapperClass1 { void drawLine(Offset p1, Offset p2, Paint paint) { assert(_offsetIsValid(p1)); assert(_offsetIsValid(p2)); - assert(paint != null); _drawLine(p1.dx, p1.dy, p2.dx, p2.dy, paint._objects, paint._data); } @@ -5234,7 +5163,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// To fill the canvas with a solid color and blend mode, consider /// [drawColor] instead. void drawPaint(Paint paint) { - assert(paint != null); _drawPaint(paint._objects, paint._data); } @@ -5248,7 +5176,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/canvas_rect_dark.png#gh-dark-mode-only) void drawRect(Rect rect, Paint paint) { assert(_rectIsValid(rect)); - assert(paint != null); _drawRect(rect.left, rect.top, rect.right, rect.bottom, paint._objects, paint._data); } @@ -5262,7 +5189,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/canvas_rrect_dark.png#gh-dark-mode-only) void drawRRect(RRect rrect, Paint paint) { assert(_rrectIsValid(rrect)); - assert(paint != null); _drawRRect(rrect._getValue32(), paint._objects, paint._data); } @@ -5277,7 +5203,6 @@ class Canvas extends NativeFieldWrapperClass1 { void drawDRRect(RRect outer, RRect inner, Paint paint) { assert(_rrectIsValid(outer)); assert(_rrectIsValid(inner)); - assert(paint != null); _drawDRRect(outer._getValue32(), inner._getValue32(), paint._objects, paint._data); } @@ -5292,7 +5217,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/canvas_oval_dark.png#gh-dark-mode-only) void drawOval(Rect rect, Paint paint) { assert(_rectIsValid(rect)); - assert(paint != null); _drawOval(rect.left, rect.top, rect.right, rect.bottom, paint._objects, paint._data); } @@ -5308,7 +5232,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/canvas_circle_dark.png#gh-dark-mode-only) void drawCircle(Offset c, double radius, Paint paint) { assert(_offsetIsValid(c)); - assert(paint != null); _drawCircle(c.dx, c.dy, radius, paint._objects, paint._data); } @@ -5331,7 +5254,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// This method is optimized for drawing arcs and should be faster than [Path.arcTo]. void drawArc(Rect rect, double startAngle, double sweepAngle, bool useCenter, Paint paint) { assert(_rectIsValid(rect)); - assert(paint != null); _drawArc(rect.left, rect.top, rect.right, rect.bottom, startAngle, sweepAngle, useCenter, paint._objects, paint._data); } @@ -5353,8 +5275,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// [Paint.style]. If the path is filled, then sub-paths within it are /// implicitly closed (see [Path.close]). void drawPath(Path path, Paint paint) { - assert(path != null); // path is checked on the engine side - assert(paint != null); _drawPath(path, paint._objects, paint._data); } @@ -5364,10 +5284,8 @@ class Canvas extends NativeFieldWrapperClass1 { /// Draws the given [Image] into the canvas with its top-left corner at the /// given [Offset]. The image is composited into the canvas using the given [Paint]. void drawImage(Image image, Offset offset, Paint paint) { - assert(image != null); // image is checked on the engine side assert(!image.debugDisposed); assert(_offsetIsValid(offset)); - assert(paint != null); final String? error = _drawImage(image._image, offset.dx, offset.dy, paint._objects, paint._data, paint.filterQuality.index); if (error != null) { throw PictureRasterizationException._(error, stack: image._debugStack); @@ -5387,11 +5305,9 @@ class Canvas extends NativeFieldWrapperClass1 { /// image) can be batched into a single call to [drawAtlas] to improve /// performance. void drawImageRect(Image image, Rect src, Rect dst, Paint paint) { - assert(image != null); // image is checked on the engine side assert(!image.debugDisposed); assert(_rectIsValid(src)); assert(_rectIsValid(dst)); - assert(paint != null); final String? error = _drawImageRect(image._image, src.left, src.top, @@ -5438,11 +5354,9 @@ class Canvas extends NativeFieldWrapperClass1 { /// cover the destination rectangle while maintaining their relative /// positions. void drawImageNine(Image image, Rect center, Rect dst, Paint paint) { - assert(image != null); // image is checked on the engine side assert(!image.debugDisposed); assert(_rectIsValid(center)); assert(_rectIsValid(dst)); - assert(paint != null); final String? error = _drawImageNine(image._image, center.left, center.top, @@ -5478,7 +5392,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// Draw the given picture onto the canvas. To create a picture, see /// [PictureRecorder]. void drawPicture(Picture picture) { - assert(picture != null); // picture is checked on the engine side assert(!picture.debugDisposed); _drawPicture(picture); } @@ -5507,7 +5420,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// described by adding half of the [ParagraphConstraints.width] given to /// [Paragraph.layout], to the `offset` argument's [Offset.dx] coordinate. void drawParagraph(Paragraph paragraph, Offset offset) { - assert(paragraph != null); assert(!paragraph.debugDisposed); assert(_offsetIsValid(offset)); assert(!paragraph._needsLayout); @@ -5526,9 +5438,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// * [drawRawPoints], which takes `points` as a [Float32List] rather than a /// [List]. void drawPoints(PointMode pointMode, List points, Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); _drawPoints(paint._objects, paint._data, pointMode.index, _encodePointList(points)); } @@ -5545,9 +5454,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// * [drawPoints], which takes `points` as a [List] rather than a /// [List]. void drawRawPoints(PointMode pointMode, Float32List points, Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); if (points.length % 2 != 0) { throw ArgumentError('"points" must have an even number of values.'); } @@ -5586,10 +5492,7 @@ class Canvas extends NativeFieldWrapperClass1 { /// rather than unencoded lists. /// * [paint], Image shaders can be used to draw images on a triangular mesh. void drawVertices(Vertices vertices, BlendMode blendMode, Paint paint) { - assert(vertices != null); // vertices is checked on the engine side assert(!vertices.debugDisposed); - assert(paint != null); - assert(blendMode != null); _drawVertices(vertices, blendMode.index, paint._objects, paint._data); } @@ -5734,12 +5637,8 @@ class Canvas extends NativeFieldWrapperClass1 { BlendMode? blendMode, Rect? cullRect, Paint paint) { - assert(atlas != null); // atlas is checked on the engine side assert(!atlas.debugDisposed); - assert(transforms != null); - assert(rects != null); assert(colors == null || colors.isEmpty || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (transforms.length != rectCount) { @@ -5938,11 +5837,7 @@ class Canvas extends NativeFieldWrapperClass1 { BlendMode? blendMode, Rect? cullRect, Paint paint) { - assert(atlas != null); // atlas is checked on the engine side - assert(rstTransforms != null); - assert(rects != null); assert(colors == null || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (rstTransforms.length != rectCount) { @@ -5985,9 +5880,6 @@ class Canvas extends NativeFieldWrapperClass1 { /// /// The arguments must not be null. void drawShadow(Path path, Color color, double elevation, bool transparentOccluder) { - assert(path != null); // path is checked on the engine side - assert(color != null); - assert(transparentOccluder != null); _drawShadow(path, color.value, elevation, transparentOccluder); } @@ -6188,9 +6080,7 @@ class Shadow { this.color = const Color(_kColorDefault), this.offset = Offset.zero, this.blurRadius = 0.0, - }) : assert(color != null, 'Text shadow color was null.'), - assert(offset != null, 'Text shadow offset was null.'), - assert(blurRadius >= 0.0, 'Text shadow blur radius should be non-negative.'); + }) : assert(blurRadius >= 0.0, 'Text shadow blur radius should be non-negative.'); static const int _kColorDefault = 0xFF000000; // Constants for shadow encoding. @@ -6277,7 +6167,6 @@ class Shadow { /// an [AnimationController]. /// {@endtemplate} static Shadow? lerp(Shadow? a, Shadow? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -6303,7 +6192,6 @@ class Shadow { /// /// {@macro dart.ui.shadow.lerp} static List? lerpList(List? a, List? b, double t) { - assert(t != null); if (a == null && b == null) { return null; } @@ -6351,25 +6239,20 @@ class Shadow { int shadowOffset = 0; for (int shadowIndex = 0; shadowIndex < shadows.length; ++shadowIndex) { final Shadow shadow = shadows[shadowIndex]; - // TODO(yjbanov): remove the null check when the framework is migrated. While the list - // of shadows contains non-nullable elements, unmigrated code can still - // pass nulls. - if (shadow != null) { - shadowOffset = shadowIndex * _kBytesPerShadow; + shadowOffset = shadowIndex * _kBytesPerShadow; - shadowsData.setInt32(_kColorOffset + shadowOffset, - shadow.color.value ^ Shadow._kColorDefault, _kFakeHostEndian); + shadowsData.setInt32(_kColorOffset + shadowOffset, + shadow.color.value ^ Shadow._kColorDefault, _kFakeHostEndian); - shadowsData.setFloat32(_kXOffset + shadowOffset, - shadow.offset.dx, _kFakeHostEndian); + shadowsData.setFloat32(_kXOffset + shadowOffset, + shadow.offset.dx, _kFakeHostEndian); - shadowsData.setFloat32(_kYOffset + shadowOffset, - shadow.offset.dy, _kFakeHostEndian); + shadowsData.setFloat32(_kYOffset + shadowOffset, + shadow.offset.dy, _kFakeHostEndian); - final double blurSigma = Shadow.convertRadiusToSigma(shadow.blurRadius); - shadowsData.setFloat32(_kBlurOffset + shadowOffset, - blurSigma, _kFakeHostEndian); - } + final double blurSigma = Shadow.convertRadiusToSigma(shadow.blurRadius); + shadowsData.setFloat32(_kBlurOffset + shadowOffset, + blurSigma, _kFakeHostEndian); } return shadowsData; diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index b0e596873cf98..f4840689031b0 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1943,8 +1943,7 @@ class Locale { const Locale( this._languageCode, [ this._countryCode, - ]) : assert(_languageCode != null), - assert(_languageCode != ''), + ]) : assert(_languageCode != ''), scriptCode = null; /// Creates a new Locale object. @@ -1971,8 +1970,7 @@ class Locale { String languageCode = 'und', this.scriptCode, String? countryCode, - }) : assert(languageCode != null), - assert(languageCode != ''), + }) : assert(languageCode != ''), _languageCode = languageCode, assert(scriptCode != ''), assert(countryCode != ''), diff --git a/lib/ui/plugins.dart b/lib/ui/plugins.dart index 50543d2acc0bc..7875232aa3c43 100644 --- a/lib/ui/plugins.dart +++ b/lib/ui/plugins.dart @@ -12,8 +12,7 @@ class CallbackHandle { /// /// Only values produced by a call to [CallbackHandle.toRawHandle] should be /// used, otherwise this object will be an invalid handle. - CallbackHandle.fromRawHandle(this._handle) - : assert(_handle != null, "'_handle' must not be null."); + CallbackHandle.fromRawHandle(this._handle); final int _handle; @@ -60,7 +59,6 @@ class PluginUtilities { /// original callback. If `callback` is not a top-level or static function, /// null is returned. static CallbackHandle? getCallbackHandle(Function callback) { - assert(callback != null, "'callback' must not be null."); return _forwardCache.putIfAbsent(callback, () { final int? handle = _getCallbackHandle(callback); return handle != null ? CallbackHandle.fromRawHandle(handle) : null; @@ -76,7 +74,6 @@ class PluginUtilities { /// [PluginUtilities.getCallbackHandle], null is returned. Otherwise, a /// tear-off of the callback associated with `handle` is returned. static Function? getCallbackFromHandle(CallbackHandle handle) { - assert(handle != null, "'handle' must not be null."); return _backwardCache.putIfAbsent( handle, () => _getCallbackFromHandle(handle.toRawHandle())); } diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 059e41ac6d316..608a4d49aded5 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -421,7 +421,7 @@ class PointerData { /// A sequence of reports about the state of pointers. class PointerDataPacket { /// Creates a packet of pointer data reports. - const PointerDataPacket({ this.data = const [] }) : assert(data != null); + const PointerDataPacket({ this.data = const [] }); /// Data about the individual pointers in this packet. /// diff --git a/lib/ui/semantics.dart b/lib/ui/semantics.dart index feb9b825d03fc..63a715eb91049 100644 --- a/lib/ui/semantics.dart +++ b/lib/ui/semantics.dart @@ -13,7 +13,7 @@ part of dart.ui; /// See also: /// - file://./../../lib/ui/semantics/semantics_node.h class SemanticsAction { - const SemanticsAction._(this.index) : assert(index != null); + const SemanticsAction._(this.index); static const int _kTapIndex = 1 << 0; static const int _kLongPressIndex = 1 << 1; @@ -289,7 +289,7 @@ class SemanticsAction { // accessibility services, `flutter_test/controller.dart#SemanticsController._importantFlags` // must be updated as well. class SemanticsFlag { - const SemanticsFlag._(this.index) : assert(index != null); + const SemanticsFlag._(this.index); /// The numerical value for this flag. /// @@ -892,10 +892,6 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { required Int32List additionalActions, }) { assert(_matrix4IsValid(transform)); - assert( - scrollChildren == 0 || scrollChildren == null || (scrollChildren > 0 && childrenInHitTestOrder != null), - 'If a node has scrollChildren, it must have childrenInHitTestOrder', - ); _updateNode( id, flags, @@ -1025,8 +1021,6 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass1 { /// [SemanticsAction.index] value. For custom actions this argument should not be /// provided. void updateCustomAction({required int id, String? label, String? hint, int overrideId = -1}) { - assert(id != null); - assert(overrideId != null); _updateCustomAction(id, label ?? '', hint ?? '', overrideId); } @Native, Int32, Handle, Handle, Int32)>(symbol: 'SemanticsUpdateBuilder::updateCustomAction') diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 5448044440be5..6468abcb38131 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -82,7 +82,6 @@ class FontWeight { /// Values for `t` are usually obtained from an [Animation], such as /// an [AnimationController]. static FontWeight? lerp(FontWeight? a, FontWeight? b, double t) { - assert(t != null); if (a == null && b == null) { return null; } @@ -141,9 +140,7 @@ class FontFeature { const FontFeature( this.feature, [ this.value = 1 ] - ) : assert(feature != null), - assert(feature.length == 4, 'Feature tag must be exactly four characters long.'), - assert(value != null), + ) : assert(feature.length == 4, 'Feature tag must be exactly four characters long.'), assert(value >= 0, 'Feature value must be zero or a positive integer.'); /// Create a [FontFeature] object that enables the feature with the given tag. @@ -958,9 +955,7 @@ class FontVariation { const FontVariation( this.axis, this.value, - ) : assert(axis != null), - assert(axis.length == 4, 'Axis tag must be exactly four characters long.'), - assert(value != null); + ) : assert(axis.length == 4, 'Axis tag must be exactly four characters long.'); /// The tag that identifies the design axis. Must consist of 4 ASCII /// characters. @@ -2258,8 +2253,7 @@ class TextPosition { const TextPosition({ required this.offset, this.affinity = TextAffinity.downstream, - }) : assert(offset != null), - assert(affinity != null); + }); /// The index of the character that immediately follows the position in the /// string representation of the text. @@ -2312,14 +2306,14 @@ class TextRange { const TextRange({ required this.start, required this.end, - }) : assert(start != null && start >= -1), - assert(end != null && end >= -1); + }) : assert(start >= -1), + assert(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) - : assert(offset != null && offset >= -1), + : assert(offset >= -1), start = offset, end = offset; @@ -2395,7 +2389,7 @@ class ParagraphConstraints { /// The [width] argument must not be null. const ParagraphConstraints({ required this.width, - }) : assert(width != null); + }); /// The width the paragraph should use whey computing the positions of glyphs. /// @@ -2790,8 +2784,6 @@ class Paragraph extends NativeFieldWrapperClass1 { /// /// See [BoxHeightStyle] and [BoxWidthStyle] for full descriptions of each option. List getBoxesForRange(int start, int end, {BoxHeightStyle boxHeightStyle = BoxHeightStyle.tight, BoxWidthStyle boxWidthStyle = BoxWidthStyle.tight}) { - assert(boxHeightStyle != null); - assert(boxWidthStyle != null); return _decodeTextBoxes(_getBoxesForRange(start, end, boxHeightStyle.index, boxWidthStyle.index)); } diff --git a/lib/web_ui/lib/geometry.dart b/lib/web_ui/lib/geometry.dart index 7d17c73f14131..029fc5038a4be 100644 --- a/lib/web_ui/lib/geometry.dart +++ b/lib/web_ui/lib/geometry.dart @@ -7,9 +7,7 @@ part of ui; abstract class OffsetBase { - const OffsetBase(this._dx, this._dy) - : assert(_dx != null), - assert(_dy != null); + const OffsetBase(this._dx, this._dy); final double _dx; final double _dy; @@ -57,7 +55,6 @@ class Offset extends OffsetBase { Offset operator %(double operand) => Offset(dx % operand, dy % operand); Rect operator &(Size other) => Rect.fromLTWH(dx, dy, other.width, other.height); static Offset? lerp(Offset? a, Offset? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -148,7 +145,6 @@ class Size extends OffsetBase { Size get flipped => Size(height, width); static Size? lerp(Size? a, Size? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -180,11 +176,7 @@ class Size extends OffsetBase { } class Rect { - const Rect.fromLTRB(this.left, this.top, this.right, this.bottom) - : assert(left != null), - assert(top != null), - assert(right != null), - assert(bottom != null); + const Rect.fromLTRB(this.left, this.top, this.right, this.bottom); const Rect.fromLTWH(double left, double top, double width, double height) : this.fromLTRB(left, top, left + width, top + height); @@ -291,7 +283,6 @@ class Rect { } static Rect? lerp(Rect? a, Rect? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -368,7 +359,6 @@ class Radius { Radius operator ~/(double operand) => Radius.elliptical((x ~/ operand).toDouble(), (y ~/ operand).toDouble()); Radius operator %(double operand) => Radius.elliptical(x % operand, y % operand); static Radius? lerp(Radius? a, Radius? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -566,19 +556,7 @@ class RRect { this.blRadiusX = 0.0, this.blRadiusY = 0.0, bool uniformRadii = false, - }) : assert(left != null), - assert(top != null), - assert(right != null), - assert(bottom != null), - assert(tlRadiusX != null), - assert(tlRadiusY != null), - assert(trRadiusX != null), - assert(trRadiusY != null), - assert(brRadiusX != null), - assert(brRadiusY != null), - assert(blRadiusX != null), - assert(blRadiusY != null), - assert(tlRadiusX >= 0), + }) : assert(tlRadiusX >= 0), assert(tlRadiusY >= 0), assert(trRadiusX >= 0), assert(trRadiusY >= 0), @@ -832,7 +810,6 @@ class RRect { } static RRect? lerp(RRect? a, RRect? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; diff --git a/lib/web_ui/lib/painting.dart b/lib/web_ui/lib/painting.dart index f887a3a04178d..0ec5a827e70c6 100644 --- a/lib/web_ui/lib/painting.dart +++ b/lib/web_ui/lib/painting.dart @@ -7,14 +7,12 @@ part of ui; // ignore: unused_element, Used in Shader assert. bool _offsetIsValid(Offset offset) { - assert(offset != null, 'Offset argument was null.'); assert(!offset.dx.isNaN && !offset.dy.isNaN, 'Offset argument contained a NaN value.'); return true; } // ignore: unused_element, Used in Shader assert. bool _matrix4IsValid(Float32List matrix4) { - assert(matrix4 != null, 'Matrix4 argument was null.'); assert(matrix4.length == 16, 'Matrix4 must have 16 entries.'); return true; } @@ -93,7 +91,6 @@ class Color { } static Color? lerp(Color? a, Color? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -145,7 +142,6 @@ class Color { } static int getAlphaFromOpacity(double opacity) { - assert(opacity != null); return (clampDouble(opacity, 0.0, 1.0) * 255).round(); } @@ -379,8 +375,7 @@ class MaskFilter { const MaskFilter.blur( this._style, this._sigma, - ) : assert(_style != null), - assert(_sigma != null); + ); final BlurStyle _style; final double _sigma; @@ -651,9 +646,7 @@ class Shadow { this.color = const Color(_kColorDefault), this.offset = Offset.zero, this.blurRadius = 0.0, - }) : assert(color != null, 'Text shadow color was null.'), - assert(offset != null, 'Text shadow offset was null.'), - assert(blurRadius >= 0.0, 'Text shadow blur radius should be non-negative.'); + }) : assert(blurRadius >= 0.0, 'Text shadow blur radius should be non-negative.'); static const int _kColorDefault = 0xFF000000; final Color color; @@ -681,7 +674,6 @@ class Shadow { } static Shadow? lerp(Shadow? a, Shadow? b, double t) { - assert(t != null); if (b == null) { if (a == null) { return null; @@ -702,7 +694,6 @@ class Shadow { } static List? lerpList(List? a, List? b, double t) { - assert(t != null); if (a == null && b == null) { return null; } diff --git a/lib/web_ui/lib/path_metrics.dart b/lib/web_ui/lib/path_metrics.dart index 5cf8df9552641..f7f509e72d1a7 100644 --- a/lib/web_ui/lib/path_metrics.dart +++ b/lib/web_ui/lib/path_metrics.dart @@ -26,9 +26,7 @@ abstract class PathMetric { } class Tangent { - const Tangent(this.position, this.vector) - : assert(position != null), - assert(vector != null); + const Tangent(this.position, this.vector); factory Tangent.fromAngle(Offset position, double angle) { return Tangent(position, Offset(math.cos(angle), math.sin(angle))); } diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 5d569d985264c..a6db5dbb11c8b 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -443,16 +443,14 @@ class Locale { const Locale( this._languageCode, [ this._countryCode, - ]) : assert(_languageCode != null), - assert(_languageCode != ''), + ]) : assert(_languageCode != ''), scriptCode = null; const Locale.fromSubtags({ String languageCode = 'und', this.scriptCode, String? countryCode, - }) : assert(languageCode != null), - assert(languageCode != ''), + }) : assert(languageCode != ''), _languageCode = languageCode, assert(scriptCode != ''), assert(countryCode != ''), diff --git a/lib/web_ui/lib/pointer.dart b/lib/web_ui/lib/pointer.dart index 254afafe5f75f..542f5c70c90c3 100644 --- a/lib/web_ui/lib/pointer.dart +++ b/lib/web_ui/lib/pointer.dart @@ -151,7 +151,6 @@ class PointerData { } class PointerDataPacket { - const PointerDataPacket({this.data = const []}) - : assert(data != null); + const PointerDataPacket({this.data = const []}); final List data; } diff --git a/lib/web_ui/lib/semantics.dart b/lib/web_ui/lib/semantics.dart index 2c4909a498675..262b6bd7bb94a 100644 --- a/lib/web_ui/lib/semantics.dart +++ b/lib/web_ui/lib/semantics.dart @@ -5,7 +5,7 @@ part of ui; class SemanticsAction { - const SemanticsAction._(this.index) : assert(index != null); + const SemanticsAction._(this.index); static const int _kTapIndex = 1 << 0; static const int _kLongPressIndex = 1 << 1; @@ -134,7 +134,7 @@ class SemanticsAction { } class SemanticsFlag { - const SemanticsFlag._(this.index) : assert(index != null); + const SemanticsFlag._(this.index); final int index; diff --git a/lib/web_ui/lib/src/engine/canvas_pool.dart b/lib/web_ui/lib/src/engine/canvas_pool.dart index 60365b892d0e3..f997b23ac4dba 100644 --- a/lib/web_ui/lib/src/engine/canvas_pool.dart +++ b/lib/web_ui/lib/src/engine/canvas_pool.dart @@ -1011,13 +1011,10 @@ class ContextStateHandle { context.translate(shaderBounds!.left, shaderBounds.top); } } - } else if (paint.color != null) { + } else { final String? colorString = colorValueToCssString(paint.color); fillStyle = colorString; strokeStyle = colorString; - } else { - fillStyle = '#000000'; - strokeStyle = '#000000'; } final ui.MaskFilter? maskFilter = paint.maskFilter; diff --git a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart index 7dda561cded51..a27aa97672e45 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_canvas.dart @@ -22,7 +22,6 @@ import 'vertices.dart'; /// An implementation of [ui.Canvas] that is backed by a CanvasKit canvas. class CanvasKitCanvas implements ui.Canvas { factory CanvasKitCanvas(ui.PictureRecorder recorder, [ui.Rect? cullRect]) { - assert(recorder != null); if (recorder.isRecording) { throw ArgumentError( '"recorder" must not already be associated with another Canvas.'); @@ -43,7 +42,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void saveLayer(ui.Rect? bounds, ui.Paint paint) { - assert(paint != null); if (bounds == null) { _saveLayerWithoutBounds(paint); } else { @@ -99,7 +97,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void transform(Float64List matrix4) { - assert(matrix4 != null); if (matrix4.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); } @@ -119,8 +116,6 @@ class CanvasKitCanvas implements ui.Canvas { void clipRect(ui.Rect rect, {ui.ClipOp clipOp = ui.ClipOp.intersect, bool doAntiAlias = true}) { assert(rectIsValid(rect)); - assert(clipOp != null); - assert(doAntiAlias != null); _clipRect(rect, clipOp, doAntiAlias); } @@ -131,7 +126,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void clipRRect(ui.RRect rrect, {bool doAntiAlias = true}) { assert(rrectIsValid(rrect)); - assert(doAntiAlias != null); _clipRRect(rrect, doAntiAlias); } @@ -141,8 +135,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void clipPath(ui.Path path, {bool doAntiAlias = true}) { - assert(path != null); // path is checked on the engine side - assert(doAntiAlias != null); _canvas.clipPath(path as CkPath, doAntiAlias); } @@ -163,8 +155,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawColor(ui.Color color, ui.BlendMode blendMode) { - assert(color != null); - assert(blendMode != null); _drawColor(color, blendMode); } @@ -176,7 +166,6 @@ class CanvasKitCanvas implements ui.Canvas { void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) { assert(offsetIsValid(p1)); assert(offsetIsValid(p2)); - assert(paint != null); _drawLine(p1, p2, paint); } @@ -186,7 +175,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawPaint(ui.Paint paint) { - assert(paint != null); _drawPaint(paint); } @@ -197,7 +185,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawRect(ui.Rect rect, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); _drawRect(rect, paint); } @@ -208,7 +195,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawRRect(ui.RRect rrect, ui.Paint paint) { assert(rrectIsValid(rrect)); - assert(paint != null); _drawRRect(rrect, paint); } @@ -220,7 +206,6 @@ class CanvasKitCanvas implements ui.Canvas { void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) { assert(rrectIsValid(outer)); assert(rrectIsValid(inner)); - assert(paint != null); _drawDRRect(outer, inner, paint); } @@ -231,7 +216,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawOval(ui.Rect rect, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); _drawOval(rect, paint); } @@ -242,7 +226,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawCircle(ui.Offset c, double radius, ui.Paint paint) { assert(offsetIsValid(c)); - assert(paint != null); _drawCircle(c, radius, paint); } @@ -254,7 +237,6 @@ class CanvasKitCanvas implements ui.Canvas { void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); _drawArc(rect, startAngle, sweepAngle, useCenter, paint); } @@ -265,47 +247,37 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawPath(ui.Path path, ui.Paint paint) { - assert(path != null); // path is checked on the engine side - assert(paint != null); _canvas.drawPath(path as CkPath, paint as CkPaint); } @override void drawImage(ui.Image image, ui.Offset p, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(offsetIsValid(p)); - assert(paint != null); _canvas.drawImage(image as CkImage, p, paint as CkPaint); } @override void drawImageRect(ui.Image image, ui.Rect src, ui.Rect dst, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(rectIsValid(src)); assert(rectIsValid(dst)); - assert(paint != null); _canvas.drawImageRect(image as CkImage, src, dst, paint as CkPaint); } @override void drawImageNine( ui.Image image, ui.Rect center, ui.Rect dst, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(rectIsValid(center)); assert(rectIsValid(dst)); - assert(paint != null); _canvas.drawImageNine(image as CkImage, center, dst, paint as CkPaint); } @override void drawPicture(ui.Picture picture) { - assert(picture != null); // picture is checked on the engine side _canvas.drawPicture(picture as CkPicture); } @override void drawParagraph(ui.Paragraph paragraph, ui.Offset offset) { - assert(paragraph != null); assert(offsetIsValid(offset)); _drawParagraph(paragraph, offset); } @@ -317,9 +289,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawPoints( ui.PointMode pointMode, List points, ui.Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); final SkFloat32List skPoints = toMallocedSkPoints(points); _canvas.drawPoints( paint as CkPaint, @@ -332,9 +301,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawRawPoints( ui.PointMode pointMode, Float32List points, ui.Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); if (points.length % 2 != 0) { throw ArgumentError('"points" must have an even number of values.'); } @@ -348,9 +314,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawVertices( ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint) { - assert(vertices != null); // vertices is checked on the engine side - assert(paint != null); - assert(blendMode != null); _canvas.drawVertices(vertices as CkVertices, blendMode, paint as CkPaint); } @@ -363,11 +326,7 @@ class CanvasKitCanvas implements ui.Canvas { ui.BlendMode? blendMode, ui.Rect? cullRect, ui.Paint paint) { - assert(atlas != null); // atlas is checked on the engine side - assert(transforms != null); - assert(rects != null); assert(colors == null || colors.isEmpty || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (transforms.length != rectCount) { @@ -415,11 +374,7 @@ class CanvasKitCanvas implements ui.Canvas { ui.BlendMode? blendMode, ui.Rect? cullRect, ui.Paint paint) { - assert(atlas != null); // atlas is checked on the engine side - assert(rstTransforms != null); - assert(rects != null); assert(colors == null || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (rstTransforms.length != rectCount) { @@ -460,9 +415,6 @@ class CanvasKitCanvas implements ui.Canvas { @override void drawShadow(ui.Path path, ui.Color color, double elevation, bool transparentOccluder) { - assert(path != null); // path is checked on the engine side - assert(color != null); - assert(transparentOccluder != null); _drawShadow(path, color, elevation, transparentOccluder); } diff --git a/lib/web_ui/lib/src/engine/canvaskit/layer.dart b/lib/web_ui/lib/src/engine/canvaskit/layer.dart index 3f09e27e0bff8..d8c98694ad1c4 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/layer.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/layer.dart @@ -472,7 +472,6 @@ class PictureLayer extends Layer { @override void paint(PaintContext paintContext) { - assert(picture != null); assert(needsPainting); paintContext.leafNodesCanvas!.save(); diff --git a/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart b/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart index addd3aa5b992b..e1f71752e63c1 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart @@ -147,7 +147,6 @@ class LayerSceneBuilder implements ui.SceneBuilder { ui.ColorFilter filter, { ui.ColorFilterEngineLayer? oldLayer, }) { - assert(filter != null); return pushLayer(ColorFilterEngineLayer(filter)); } @@ -157,7 +156,6 @@ class LayerSceneBuilder implements ui.SceneBuilder { ui.ImageFilterEngineLayer? oldLayer, ui.Offset offset = ui.Offset.zero, }) { - assert(filter != null); return pushLayer(ImageFilterEngineLayer(filter, offset)); } diff --git a/lib/web_ui/lib/src/engine/canvaskit/path.dart b/lib/web_ui/lib/src/engine/canvaskit/path.dart index 27479588f4b84..fe60fc2837194 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/path.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/path.dart @@ -86,7 +86,6 @@ class CkPath extends ManagedSkiaObject implements ui.Path { @override void addPolygon(List points, bool close) { - assert(points != null); final SkFloat32List encodedPoints = toMallocedSkPoints(points); skiaObject.addPoly(encodedPoints.toTypedArray(), close); free(encodedPoints); diff --git a/lib/web_ui/lib/src/engine/canvaskit/shader.dart b/lib/web_ui/lib/src/engine/canvaskit/shader.dart index 86888480aa3db..c2e9bbb0c3a4b 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/shader.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/shader.dart @@ -47,10 +47,6 @@ class CkGradientSweep extends CkShader implements ui.Gradient { CkGradientSweep(this.center, this.colors, this.colorStops, this.tileMode, this.startAngle, this.endAngle, this.matrix4) : assert(offsetIsValid(center)), - assert(colors != null), - assert(tileMode != null), - assert(startAngle != null), - assert(endAngle != null), assert(startAngle < endAngle), assert(matrix4 == null || matrix4IsValid(matrix4)) { validateColorStops(colors, colorStops); @@ -96,8 +92,6 @@ class CkGradientLinear extends CkShader implements ui.Gradient { Float32List? matrix, ) : assert(offsetIsValid(from)), assert(offsetIsValid(to)), - assert(colors != null), - assert(tileMode != null), matrix4 = matrix { if (assertionsEnabled) { assert(matrix4 == null || matrix4IsValid(matrix4!)); diff --git a/lib/web_ui/lib/src/engine/canvaskit/surface.dart b/lib/web_ui/lib/src/engine/canvaskit/surface.dart index 1d24687d118ef..80ef7e1da8c4d 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/surface.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/surface.dart @@ -26,9 +26,7 @@ typedef SubmitCallback = bool Function(SurfaceFrame, CkCanvas); /// A frame which contains a canvas to be drawn into. class SurfaceFrame { SurfaceFrame(this.skiaSurface, this.submitCallback) - : _submitted = false, - assert(skiaSurface != null), - assert(submitCallback != null); + : _submitted = false; final CkSurface skiaSurface; final SubmitCallback submitCallback; diff --git a/lib/web_ui/lib/src/engine/canvaskit/vertices.dart b/lib/web_ui/lib/src/engine/canvaskit/vertices.dart index 4d34d34dfd243..df2b38c127db3 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/vertices.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/vertices.dart @@ -18,8 +18,6 @@ class CkVertices extends ManagedSkiaObject implements ui.Vertices { List? colors, List? indices, }) { - assert(mode != null); - assert(positions != null); if (textureCoordinates != null && textureCoordinates.length != positions.length) { throw ArgumentError( @@ -50,8 +48,6 @@ class CkVertices extends ManagedSkiaObject implements ui.Vertices { Int32List? colors, Uint16List? indices, }) { - assert(mode != null); - assert(positions != null); if (textureCoordinates != null && textureCoordinates.length != positions.length) { throw ArgumentError( diff --git a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart index 8725b382fcef7..55add4bba234d 100644 --- a/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart @@ -38,8 +38,7 @@ class BitmapCanvas extends EngineCanvas { /// initialize this canvas. BitmapCanvas(this._bounds, RenderStrategy renderStrategy, {double density = 1.0}) - : assert(_bounds != null), - _density = density, + : _density = density, _renderStrategy = renderStrategy, widthInBitmapPixels = widthToPhysical(_bounds.width), heightInBitmapPixels = heightToPhysical(_bounds.height), @@ -69,7 +68,6 @@ class BitmapCanvas extends EngineCanvas { /// Painting outside these bounds will result in cropping. ui.Rect get bounds => _bounds; set bounds(ui.Rect newValue) { - assert(newValue != null); _bounds = newValue; final int newCanvasPositionX = _bounds.left.floor() - kPaddingPixels; final int newCanvasPositionY = _bounds.top.floor() - kPaddingPixels; @@ -217,7 +215,6 @@ class BitmapCanvas extends EngineCanvas { // Used by picture to assess if canvas is large enough to reuse as is. bool doesFitBounds(ui.Rect newBounds, double newDensity) { - assert(newBounds != null); return widthInBitmapPixels >= widthToPhysical(newBounds.width) && heightInBitmapPixels >= heightToPhysical(newBounds.height) && _density == newDensity; @@ -1334,7 +1331,6 @@ String? stringForStrokeCap(ui.StrokeCap? strokeCap) { } String stringForStrokeJoin(ui.StrokeJoin strokeJoin) { - assert(strokeJoin != null); switch (strokeJoin) { case ui.StrokeJoin.round: return 'round'; diff --git a/lib/web_ui/lib/src/engine/html/canvas.dart b/lib/web_ui/lib/src/engine/html/canvas.dart index b40df52a28ffa..eb2b9b12de064 100644 --- a/lib/web_ui/lib/src/engine/html/canvas.dart +++ b/lib/web_ui/lib/src/engine/html/canvas.dart @@ -36,7 +36,6 @@ class SurfaceCanvas implements ui.Canvas { @override void saveLayer(ui.Rect? bounds, ui.Paint paint) { - assert(paint != null); if (bounds == null) { _saveLayerWithoutBounds(paint); } else { @@ -90,7 +89,6 @@ class SurfaceCanvas implements ui.Canvas { @override void transform(Float64List matrix4) { - assert(matrix4 != null); if (matrix4.length != 16) { throw ArgumentError('"matrix4" must have 16 entries.'); } @@ -110,8 +108,6 @@ class SurfaceCanvas implements ui.Canvas { void clipRect(ui.Rect rect, {ui.ClipOp clipOp = ui.ClipOp.intersect, bool doAntiAlias = true}) { assert(rectIsValid(rect)); - assert(clipOp != null); - assert(doAntiAlias != null); _clipRect(rect, clipOp, doAntiAlias); } @@ -122,7 +118,6 @@ class SurfaceCanvas implements ui.Canvas { @override void clipRRect(ui.RRect rrect, {bool doAntiAlias = true}) { assert(rrectIsValid(rrect)); - assert(doAntiAlias != null); _clipRRect(rrect, doAntiAlias); } @@ -132,8 +127,6 @@ class SurfaceCanvas implements ui.Canvas { @override void clipPath(ui.Path path, {bool doAntiAlias = true}) { - assert(path != null); // path is checked on the engine side - assert(doAntiAlias != null); _clipPath(path, doAntiAlias); } @@ -171,8 +164,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawColor(ui.Color color, ui.BlendMode blendMode) { - assert(color != null); - assert(blendMode != null); _drawColor(color, blendMode); } @@ -184,7 +175,6 @@ class SurfaceCanvas implements ui.Canvas { void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) { assert(offsetIsValid(p1)); assert(offsetIsValid(p2)); - assert(paint != null); _drawLine(p1, p2, paint); } @@ -194,7 +184,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawPaint(ui.Paint paint) { - assert(paint != null); _drawPaint(paint); } @@ -205,7 +194,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawRect(ui.Rect rect, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); _drawRect(rect, paint); } @@ -216,7 +204,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawRRect(ui.RRect rrect, ui.Paint paint) { assert(rrectIsValid(rrect)); - assert(paint != null); _drawRRect(rrect, paint); } @@ -228,7 +215,6 @@ class SurfaceCanvas implements ui.Canvas { void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) { assert(rrectIsValid(outer)); assert(rrectIsValid(inner)); - assert(paint != null); _drawDRRect(outer, inner, paint); } @@ -239,7 +225,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawOval(ui.Rect rect, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); _drawOval(rect, paint); } @@ -250,7 +235,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawCircle(ui.Offset c, double radius, ui.Paint paint) { assert(offsetIsValid(c)); - assert(paint != null); _drawCircle(c, radius, paint); } @@ -262,7 +246,6 @@ class SurfaceCanvas implements ui.Canvas { void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter, ui.Paint paint) { assert(rectIsValid(rect)); - assert(paint != null); const double pi = math.pi; const double pi2 = 2.0 * pi; @@ -297,8 +280,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawPath(ui.Path path, ui.Paint paint) { - assert(path != null); // path is checked on the engine side - assert(paint != null); _drawPath(path, paint); } @@ -308,9 +289,7 @@ class SurfaceCanvas implements ui.Canvas { @override void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(offsetIsValid(offset)); - assert(paint != null); _drawImage(image, offset, paint); } @@ -320,10 +299,8 @@ class SurfaceCanvas implements ui.Canvas { @override void drawImageRect(ui.Image image, ui.Rect src, ui.Rect dst, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(rectIsValid(src)); assert(rectIsValid(dst)); - assert(paint != null); _drawImageRect(image, src, dst, paint); } @@ -376,10 +353,8 @@ class SurfaceCanvas implements ui.Canvas { @override void drawImageNine( ui.Image image, ui.Rect center, ui.Rect dst, ui.Paint paint) { - assert(image != null); // image is checked on the engine side assert(rectIsValid(center)); assert(rectIsValid(dst)); - assert(paint != null); if (dst.isEmpty) { return; @@ -424,13 +399,11 @@ class SurfaceCanvas implements ui.Canvas { @override void drawPicture(ui.Picture picture) { - assert(picture != null); // picture is checked on the engine side _canvas.drawPicture(picture); } @override void drawParagraph(ui.Paragraph paragraph, ui.Offset offset) { - assert(paragraph != null); assert(offsetIsValid(offset)); _drawParagraph(paragraph, offset); } @@ -442,9 +415,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawPoints( ui.PointMode pointMode, List points, ui.Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); final Float32List pointList = offsetListToFloat32List(points); drawRawPoints(pointMode, pointList, paint); } @@ -452,9 +422,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawRawPoints( ui.PointMode pointMode, Float32List points, ui.Paint paint) { - assert(pointMode != null); - assert(points != null); - assert(paint != null); if (points.length % 2 != 0) { throw ArgumentError('"points" must have an even number of values.'); } @@ -464,9 +431,6 @@ class SurfaceCanvas implements ui.Canvas { @override void drawVertices( ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint) { - //assert(vertices != null); // vertices is checked on the engine side - assert(paint != null); - assert(blendMode != null); _canvas.drawVertices( vertices as SurfaceVertices, blendMode, paint as SurfacePaint); } @@ -481,11 +445,7 @@ class SurfaceCanvas implements ui.Canvas { ui.Rect? cullRect, ui.Paint paint, ) { - assert(atlas != null); // atlas is checked on the engine side - assert(transforms != null); - assert(rects != null); assert(colors == null || colors.isEmpty || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (transforms.length != rectCount) { @@ -510,11 +470,7 @@ class SurfaceCanvas implements ui.Canvas { ui.Rect? cullRect, ui.Paint paint, ) { - assert(atlas != null); // atlas is checked on the engine side - assert(rstTransforms != null); - assert(rects != null); assert(colors == null || blendMode != null); - assert(paint != null); final int rectCount = rects.length; if (rstTransforms.length != rectCount) { @@ -540,9 +496,6 @@ class SurfaceCanvas implements ui.Canvas { double elevation, bool transparentOccluder, ) { - assert(path != null); // path is checked on the engine side - assert(color != null); - assert(transparentOccluder != null); _canvas.drawShadow(path, color, elevation, transparentOccluder); } } diff --git a/lib/web_ui/lib/src/engine/html/dom_canvas.dart b/lib/web_ui/lib/src/engine/html/dom_canvas.dart index c450f744c527f..0e79b3e08baf8 100644 --- a/lib/web_ui/lib/src/engine/html/dom_canvas.dart +++ b/lib/web_ui/lib/src/engine/html/dom_canvas.dart @@ -257,8 +257,7 @@ DomHTMLElement buildDrawRectElement( ..transformOrigin = '0 0 0' ..transform = effectiveTransform; - String cssColor = - paint.color == null ? '#000000' : colorValueToCssString(paint.color)!; + String cssColor = colorValueToCssString(paint.color)!; if (paint.maskFilter != null) { final double sigma = paint.maskFilter!.webOnlySigma; @@ -352,10 +351,8 @@ SVGSVGElement pathToSvgElement(SurfacePath path, SurfacePaintData paint) { svgPath.setAttribute('stroke-linecap', '${stringForStrokeCap(paint.strokeCap)}'); } svgPath.setAttribute('fill', 'none'); - } else if (paint.color != null) { - svgPath.setAttribute('fill', colorValueToCssString(paint.color)!); } else { - svgPath.setAttribute('fill', '#000000'); + svgPath.setAttribute('fill', colorValueToCssString(paint.color)!); } if (path.fillType == ui.PathFillType.evenOdd) { svgPath.setAttribute('fill-rule', 'evenodd'); diff --git a/lib/web_ui/lib/src/engine/html/painting.dart b/lib/web_ui/lib/src/engine/html/painting.dart index bdd8aa4fd8251..78e5f64239f7c 100644 --- a/lib/web_ui/lib/src/engine/html/painting.dart +++ b/lib/web_ui/lib/src/engine/html/painting.dart @@ -161,7 +161,7 @@ class SurfacePaint implements ui.Paint { @override set strokeMiterLimit(double value) { - assert(value != null); + } @override @@ -268,9 +268,7 @@ class SurfacePaintData { if (strokeJoin != null) { buffer.write('strokeJoin = $strokeJoin; '); } - if (color != null) { - buffer.write('color = ${colorToCssString(ui.Color(color))}; '); - } + buffer.write('color = ${colorToCssString(ui.Color(color))}; '); if (shader != null) { buffer.write('shader = $shader; '); } diff --git a/lib/web_ui/lib/src/engine/html/picture.dart b/lib/web_ui/lib/src/engine/html/picture.dart index da6f988ba8df7..542d71fcb6578 100644 --- a/lib/web_ui/lib/src/engine/html/picture.dart +++ b/lib/web_ui/lib/src/engine/html/picture.dart @@ -54,8 +54,7 @@ class PaintRequest { PaintRequest({ required this.canvasSize, required this.paintCallback, - }) : assert(canvasSize != null), - assert(paintCallback != null); + }); final ui.Size canvasSize; final ui.VoidCallback paintCallback; diff --git a/lib/web_ui/lib/src/engine/html/render_vertices.dart b/lib/web_ui/lib/src/engine/html/render_vertices.dart index 9480bd952c3f0..1626d1736293b 100644 --- a/lib/web_ui/lib/src/engine/html/render_vertices.dart +++ b/lib/web_ui/lib/src/engine/html/render_vertices.dart @@ -26,9 +26,7 @@ class SurfaceVertices implements ui.Vertices { List positions, { List? colors, List? indices, - }) : assert(mode != null), - assert(positions != null), - colors = colors != null ? _int32ListFromColors(colors) : null, + }) : colors = colors != null ? _int32ListFromColors(colors) : null, indices = indices != null ? Uint16List.fromList(indices) : null, positions = offsetListToFloat32List(positions) { initWebGl(); @@ -39,8 +37,7 @@ class SurfaceVertices implements ui.Vertices { this.positions, { this.colors, this.indices, - }) : assert(mode != null), - assert(positions != null) { + }) { initWebGl(); } @@ -192,7 +189,6 @@ class _WebGlRenderer implements GlRenderer { // // Create buffer for vertex coordinates. final Object positionsBuffer = gl.createBuffer()!; - assert(positionsBuffer != null); Object? vao; if (imageShader != null) { @@ -383,7 +379,6 @@ class _WebGlRenderer implements GlRenderer { // Setup geometry. final Object positionsBuffer = gl.createBuffer()!; - assert(positionsBuffer != null); gl.bindArrayBuffer(positionsBuffer); gl.bufferData(vertices, gl.kStaticDraw); // Point an attribute to the currently bound vertex buffer object. @@ -458,7 +453,6 @@ class _WebGlRenderer implements GlRenderer { @override void drawHairline( DomCanvasRenderingContext2D? ctx, Float32List positions) { - assert(positions != null); final int pointCount = positions.length ~/ 2; ctx!.lineWidth = 1.0; ctx.beginPath(); diff --git a/lib/web_ui/lib/src/engine/html/scene_builder.dart b/lib/web_ui/lib/src/engine/html/scene_builder.dart index bd84aeaf9a992..6453c19a5a0ae 100644 --- a/lib/web_ui/lib/src/engine/html/scene_builder.dart +++ b/lib/web_ui/lib/src/engine/html/scene_builder.dart @@ -136,7 +136,6 @@ class SurfaceSceneBuilder implements ui.SceneBuilder { ui.Clip clipBehavior = ui.Clip.antiAlias, ui.ClipRectEngineLayer? oldLayer, }) { - assert(clipBehavior != null); return _pushSurface( PersistedClipRect(oldLayer as PersistedClipRect?, rect, clipBehavior)); } @@ -167,7 +166,6 @@ class SurfaceSceneBuilder implements ui.SceneBuilder { ui.Clip clipBehavior = ui.Clip.antiAlias, ui.ClipPathEngineLayer? oldLayer, }) { - assert(clipBehavior != null); return _pushSurface( PersistedClipPath(oldLayer as PersistedClipPath?, path, clipBehavior)); } @@ -205,7 +203,6 @@ class SurfaceSceneBuilder implements ui.SceneBuilder { ui.ColorFilter filter, { ui.ColorFilterEngineLayer? oldLayer, }) { - assert(filter != null); return _pushSurface( PersistedColorFilter(oldLayer as PersistedColorFilter?, filter)); } @@ -226,7 +223,6 @@ class SurfaceSceneBuilder implements ui.SceneBuilder { ui.Offset offset = ui.Offset.zero, ui.ImageFilterEngineLayer? oldLayer, }) { - assert(filter != null); return _pushSurface( PersistedImageFilter(oldLayer as PersistedImageFilter?, filter, offset)); } @@ -264,7 +260,6 @@ class SurfaceSceneBuilder implements ui.SceneBuilder { ui.ShaderMaskEngineLayer? oldLayer, ui.FilterQuality filterQuality = ui.FilterQuality.low, }) { - assert(blendMode != null); return _pushSurface(PersistedShaderMask( oldLayer as PersistedShaderMask?, shader, maskRect, blendMode, filterQuality)); diff --git a/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart b/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart index 0caede789b3e7..59801155ad9a5 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart @@ -187,7 +187,6 @@ class EngineImageShader implements ui.ImageShader { /// /// Create buffer for vertex coordinates. final Object positionsBuffer = gl.createBuffer()!; - assert(positionsBuffer != null); Object? vao; if (isWebGl2) { diff --git a/lib/web_ui/lib/src/engine/html/shaders/shader.dart b/lib/web_ui/lib/src/engine/html/shaders/shader.dart index e438165383486..ac83b020c8b75 100644 --- a/lib/web_ui/lib/src/engine/html/shaders/shader.dart +++ b/lib/web_ui/lib/src/engine/html/shaders/shader.dart @@ -69,11 +69,6 @@ class GradientSweep extends EngineGradient { GradientSweep(this.center, this.colors, this.colorStops, this.tileMode, this.startAngle, this.endAngle, this.matrix4) : assert(offsetIsValid(center)), - assert(colors != null), - assert(tileMode != null), - assert(startAngle != null), - assert(endAngle != null), - assert(startAngle < endAngle), super._() { validateColorStops(colors, colorStops); } @@ -189,8 +184,6 @@ class GradientLinear extends EngineGradient { Float32List? matrix, ) : assert(offsetIsValid(from)), assert(offsetIsValid(to)), - assert(colors != null), - assert(tileMode != null), matrix4 = matrix == null ? null : FastMatrix32(matrix), super._() { if (assertionsEnabled) { diff --git a/lib/web_ui/lib/src/engine/html/surface.dart b/lib/web_ui/lib/src/engine/html/surface.dart index 15cc063c14597..425677f2c45c1 100644 --- a/lib/web_ui/lib/src/engine/html/surface.dart +++ b/lib/web_ui/lib/src/engine/html/surface.dart @@ -223,7 +223,6 @@ abstract class PersistedSurface implements ui.EngineLayer { /// surface. PersistedSurfaceState get state => _state; set state(PersistedSurfaceState newState) { - assert(newState != null); assert(newState != _state, 'Attempted to set state that the surface is already in. This likely indicates a bug in the compositor.'); assert(_debugValidateStateTransition(newState)); @@ -414,7 +413,6 @@ abstract class PersistedSurface implements ui.EngineLayer { /// creates a new element by calling [build]. @mustCallSuper void update(covariant PersistedSurface oldSurface) { - assert(oldSurface != null); assert(!identical(oldSurface, this)); assert(debugAssertSurfaceState(this, PersistedSurfaceState.created)); assert(debugAssertSurfaceState(oldSurface, PersistedSurfaceState.active, @@ -1049,7 +1047,6 @@ abstract class PersistedContainerSurface extends PersistedSurface { final PersistedSurface child = _children[i]; final DomHTMLElement childElement = child.rootElement! as DomHTMLElement; - assert(childElement != null); if (!isStationary) { if (refNode == null) { containerElement!.append(childElement); diff --git a/lib/web_ui/lib/src/engine/html/surface_stats.dart b/lib/web_ui/lib/src/engine/html/surface_stats.dart index 841c318c441ed..f92194f196f89 100644 --- a/lib/web_ui/lib/src/engine/html/surface_stats.dart +++ b/lib/web_ui/lib/src/engine/html/surface_stats.dart @@ -237,7 +237,6 @@ void debugPrintSurfaceStats(PersistedScene scene, int frameNumber) { void countReusesRecursively(PersistedSurface surface) { final DebugSurfaceStats stats = surfaceStatsFor(surface); - assert(stats != null); surfaceRetainCount += stats.retainSurfaceCount; elementReuseCount += stats.reuseElementCount; diff --git a/lib/web_ui/lib/src/engine/initialization.dart b/lib/web_ui/lib/src/engine/initialization.dart index ef0ad54ab1a1b..bbf346d3c2e5a 100644 --- a/lib/web_ui/lib/src/engine/initialization.dart +++ b/lib/web_ui/lib/src/engine/initialization.dart @@ -252,7 +252,6 @@ AssetManager get assetManager => _assetManager!; AssetManager? _assetManager; void _setAssetManager(AssetManager assetManager) { - assert(assetManager != null, 'Cannot set assetManager to null'); if (assetManager == _assetManager) { return; } diff --git a/lib/web_ui/lib/src/engine/navigation/history.dart b/lib/web_ui/lib/src/engine/navigation/history.dart index b57557ce9ee04..d785449095d4f 100644 --- a/lib/web_ui/lib/src/engine/navigation/history.dart +++ b/lib/web_ui/lib/src/engine/navigation/history.dart @@ -359,7 +359,6 @@ class SingleEntryBrowserHistory extends BrowserHistory { /// replaces the state of the entry so that we can recognize it later using /// [_isOriginEntry] inside [_popStateListener]. void _setupOriginEntry(UrlStrategy strategy) { - assert(strategy != null); strategy.replaceState(_wrapOriginState(currentState), 'origin', ''); } @@ -370,7 +369,6 @@ class SingleEntryBrowserHistory extends BrowserHistory { bool replace = false, String? path, }) { - assert(strategy != null); path ??= currentPath; if (replace) { strategy.replaceState(_flutterState, 'flutter', path); diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index fc717f52b6ac1..dc116ab9f3b90 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -817,9 +817,6 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { required DomPointerEvent event, required _SanitizedDetails details, }) { - assert(data != null); - assert(event != null); - assert(details != null); final ui.PointerDeviceKind kind = _pointerTypeToDeviceKind(event.pointerType!); final double tilt = _computeHighestTilt(event); final Duration timeStamp = _BaseAdapter._eventTimeStampToDuration(event.timeStamp!); @@ -1147,9 +1144,6 @@ class _MouseAdapter extends _BaseAdapter with _WheelEventListenerMixin { required DomMouseEvent event, required _SanitizedDetails details, }) { - assert(data != null); - assert(event != null); - assert(details != null); final ui.Offset offset = computeEventOffsetToTarget(event, glassPaneElement); _pointerDataConverter.convert( data, diff --git a/lib/web_ui/lib/src/engine/pointer_converter.dart b/lib/web_ui/lib/src/engine/pointer_converter.dart index 568577fe30bde..e6275174c9fe8 100644 --- a/lib/web_ui/lib/src/engine/pointer_converter.dart +++ b/lib/web_ui/lib/src/engine/pointer_converter.dart @@ -240,7 +240,6 @@ class PointerDataConverter { print('>> device=$device change=$change buttons=$buttons'); } final bool isDown = buttons != 0; - assert(change != null); if (signalKind == null || signalKind == ui.PointerSignalKind.none) { switch (change) { diff --git a/lib/web_ui/lib/src/engine/semantics/semantics.dart b/lib/web_ui/lib/src/engine/semantics/semantics.dart index 878a14882f6a8..d3d659ccb42b2 100644 --- a/lib/web_ui/lib/src/engine/semantics/semantics.dart +++ b/lib/web_ui/lib/src/engine/semantics/semantics.dart @@ -381,8 +381,7 @@ abstract class RoleManager { /// Initializes a role for [semanticsObject]. /// /// A single role object manages exactly one [SemanticsObject]. - RoleManager(this.role, this.semanticsObject) - : assert(semanticsObject != null); + RoleManager(this.role, this.semanticsObject); /// Role identifier. final Role role; @@ -869,7 +868,6 @@ class SemanticsObject { void updateSelf(SemanticsNodeUpdate update) { // Update all field values and their corresponding dirty flags before // applying the updates to the DOM. - assert(update.flags != null); if (_flags != update.flags) { _flags = update.flags; _markFlagsDirty(); @@ -1478,8 +1476,6 @@ class EngineSemanticsOwner { /// allows the same node to be detached from one parent in the tree and /// reattached to another parent. void _attachObject({required SemanticsObject parent, required SemanticsObject child}) { - assert(child != null); - assert(parent != null); child._parent = parent; _attachments[child.id] = parent; } @@ -1616,13 +1612,7 @@ class EngineSemanticsOwner { /// the Web Engine. /// /// The default mode is [AccessibilityMode.unknown]. - AccessibilityMode get mode => _mode; - set mode(AccessibilityMode value) { - assert(value != null); - _mode = value; - } - - AccessibilityMode _mode = AccessibilityMode.unknown; + AccessibilityMode mode = AccessibilityMode.unknown; /// Currently used [GestureMode]. /// @@ -1764,7 +1754,7 @@ class EngineSemanticsOwner { /// not accompanied by pointer events. In the presence of pointer events, /// delegate to Flutter's gesture detection system to produce gestures. bool shouldAcceptBrowserGesture(String eventType) { - if (_mode == AccessibilityMode.known) { + if (mode == AccessibilityMode.known) { // Do not ignore accessibility gestures in known mode, unless semantics // is explicitly disabled. return semanticsEnabled; diff --git a/lib/web_ui/lib/src/engine/services/buffers.dart b/lib/web_ui/lib/src/engine/services/buffers.dart index 1112e868e252d..fba3823a24744 100644 --- a/lib/web_ui/lib/src/engine/services/buffers.dart +++ b/lib/web_ui/lib/src/engine/services/buffers.dart @@ -212,8 +212,6 @@ abstract class _TypedDataBuffer extends ListBase { /// Like [insertAll], but with a guaranteed non-`null` [start] and [end]. void _insertKnownLength(int index, Iterable values, int start, int end) { - assert(values != null); - assert(end != null); if (start > values.length || end > values.length) { throw StateError('Too few elements'); } diff --git a/lib/web_ui/lib/src/engine/services/message_codec.dart b/lib/web_ui/lib/src/engine/services/message_codec.dart index cb8c26b74647b..c8f9e7d8da801 100644 --- a/lib/web_ui/lib/src/engine/services/message_codec.dart +++ b/lib/web_ui/lib/src/engine/services/message_codec.dart @@ -32,7 +32,7 @@ abstract class MessageCodec { class MethodCall { /// Creates a [MethodCall] representing the invocation of [method] with the /// specified [arguments]. - const MethodCall(this.method, [this.arguments]) : assert(method != null); + const MethodCall(this.method, [this.arguments]); /// The name of the method to be called. final String method; @@ -101,7 +101,7 @@ class PlatformException implements Exception { required this.code, this.message, this.details, - }) : assert(code != null); + }); /// An error code. final String code; diff --git a/lib/web_ui/lib/src/engine/services/message_codecs.dart b/lib/web_ui/lib/src/engine/services/message_codecs.dart index d084c9730cf25..e412e4266296e 100644 --- a/lib/web_ui/lib/src/engine/services/message_codecs.dart +++ b/lib/web_ui/lib/src/engine/services/message_codecs.dart @@ -160,7 +160,6 @@ class JSONMethodCodec implements MethodCodec { @override ByteData? encodeErrorEnvelope( {required String code, String? message, dynamic details}) { - assert(code != null); return const JSONMessageCodec() .encodeMessage([code, message, details]); } diff --git a/lib/web_ui/lib/src/engine/services/serialization.dart b/lib/web_ui/lib/src/engine/services/serialization.dart index 1188abcb4e18a..e428e6a3f06c7 100644 --- a/lib/web_ui/lib/src/engine/services/serialization.dart +++ b/lib/web_ui/lib/src/engine/services/serialization.dart @@ -122,7 +122,7 @@ class WriteBuffer { /// The byte order used is [Endian.host] throughout. class ReadBuffer { /// Creates a [ReadBuffer] for reading from the specified [data]. - ReadBuffer(this.data) : assert(data != null); + ReadBuffer(this.data); /// The underlying data being read. final ByteData data; diff --git a/lib/web_ui/lib/src/engine/text/paragraph.dart b/lib/web_ui/lib/src/engine/text/paragraph.dart index c24b476290049..165e40e7220ff 100644 --- a/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -778,8 +778,6 @@ void applyTextStyleToElement({ required DomElement element, required EngineTextStyle style, }) { - assert(element != null); - assert(style != null); bool updateDecoration = false; final DomCSSStyleDeclaration cssStyle = element.style; diff --git a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index dd89519d36263..27b574808228e 100644 --- a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -360,7 +360,6 @@ class AutofillInfo { factory AutofillInfo.fromFrameworkMessage(Map autofill, {TextCapitalizationConfig textCapitalization = const TextCapitalizationConfig.defaultCapitalization()}) { - assert(autofill != null); final String uniqueIdentifier = autofill.readString('uniqueIdentifier'); final List? hintsList = autofill.tryList('hints'); final String? firstHint = (hintsList == null || hintsList.isEmpty) ? null : hintsList.first as String; diff --git a/lib/web_ui/lib/src/engine/validators.dart b/lib/web_ui/lib/src/engine/validators.dart index 64c3dd5a2ed95..5db10f9dc8289 100644 --- a/lib/web_ui/lib/src/engine/validators.dart +++ b/lib/web_ui/lib/src/engine/validators.dart @@ -7,7 +7,6 @@ import 'dart:typed_data'; import 'package:ui/ui.dart' as ui; bool rectIsValid(ui.Rect rect) { - assert(rect != null, 'Rect argument was null.'); assert( !(rect.left.isNaN || rect.right.isNaN || @@ -18,7 +17,6 @@ bool rectIsValid(ui.Rect rect) { } bool rrectIsValid(ui.RRect rrect) { - assert(rrect != null, 'RRect argument was null.'); assert( !(rrect.left.isNaN || rrect.right.isNaN || @@ -29,20 +27,17 @@ bool rrectIsValid(ui.RRect rrect) { } bool offsetIsValid(ui.Offset offset) { - assert(offset != null, 'Offset argument was null.'); assert(!offset.dx.isNaN && !offset.dy.isNaN, 'Offset argument contained a NaN value.'); return true; } bool matrix4IsValid(Float32List matrix4) { - assert(matrix4 != null, 'Matrix4 argument was null.'); assert(matrix4.length == 16, 'Matrix4 must have 16 entries.'); return true; } bool radiusIsValid(ui.Radius radius) { - assert(radius != null, 'Radius argument was null.'); assert(!radius.x.isNaN && !radius.y.isNaN, 'Radius argument contained a NaN value.'); return true; diff --git a/lib/web_ui/lib/text.dart b/lib/web_ui/lib/text.dart index 7c7e3c6c100a1..3ad62f0fafc90 100644 --- a/lib/web_ui/lib/text.dart +++ b/lib/web_ui/lib/text.dart @@ -45,7 +45,6 @@ class FontWeight { w900 ]; static FontWeight? lerp(FontWeight? a, FontWeight? b, double t) { - assert(t != null); if (a == null && b == null) { return null; } @@ -75,10 +74,8 @@ class FontWeight { class FontFeature { const FontFeature(this.feature, [this.value = 1]) - : assert(feature != null), - assert(feature.length == 4, + : assert(feature.length == 4, 'Feature tag must be exactly four characters long.'), - assert(value != null), assert(value >= 0, 'Feature value must be zero or a positive integer.'); const FontFeature.enable(String feature) : this(feature, 1); const FontFeature.disable(String feature) : this(feature, 0); @@ -184,9 +181,7 @@ class FontVariation { const FontVariation( this.axis, this.value, - ) : assert(axis != null), - assert(axis.length == 4, 'Axis tag must be exactly four characters long.'), - assert(value != null); + ) : assert(axis.length == 4, 'Axis tag must be exactly four characters long.'); final String axis; final double value; @@ -519,8 +514,7 @@ class TextPosition { const TextPosition({ required this.offset, this.affinity = TextAffinity.downstream, - }) : assert(offset != null), - assert(affinity != null); + }); final int offset; final TextAffinity affinity; @@ -595,7 +589,7 @@ class TextRange { class ParagraphConstraints { const ParagraphConstraints({ required this.width, - }) : assert(width != null); + }); final double width; @override diff --git a/lib/web_ui/lib/window.dart b/lib/web_ui/lib/window.dart index 99e236a203614..70d49f55667c4 100644 --- a/lib/web_ui/lib/window.dart +++ b/lib/web_ui/lib/window.dart @@ -158,8 +158,7 @@ enum Brightness { // Unimplemented classes. // TODO(dit): see https://github.com/flutter/flutter/issues/33614. class CallbackHandle { - CallbackHandle.fromRawHandle(this._handle) - : assert(_handle != null, "'_handle' must not be null."); + CallbackHandle.fromRawHandle(this._handle); final int _handle; diff --git a/testing/dart/color_filter_test.dart b/testing/dart/color_filter_test.dart index ad4a324c14c68..e5553604da9b2 100644 --- a/testing/dart/color_filter_test.dart +++ b/testing/dart/color_filter_test.dart @@ -76,7 +76,6 @@ void main() { builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - expect(scene != null, true); await scene.toImage(100, 100); }); @@ -108,7 +107,6 @@ void main() { builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - expect(scene != null, true); await scene.toImage(100, 100); }); diff --git a/testing/dart/color_test.dart b/testing/dart/color_test.dart index 55105ed80f7db..8876fa8da4cfc 100644 --- a/testing/dart/color_test.dart +++ b/testing/dart/color_test.dart @@ -27,23 +27,15 @@ void main() { }); test('color created with out of bounds value', () { - try { - const Color c = Color(0x100 << 24); - final Paint p = Paint(); - p.color = c; - } catch (e) { - expect(e != null, equals(true)); - } + const Color c = Color(0x100 << 24); + final Paint p = Paint(); + p.color = c; }); test('color created with wildly out of bounds value', () { - try { - const Color c = Color(1 << 1000000); - final Paint p = Paint(); - p.color = c; - } catch (e) { - expect(e != null, equals(true)); - } + const Color c = Color(1 << 1000000); + final Paint p = Paint(); + p.color = c; }); test('two colors are only == if they have the same runtime type', () { diff --git a/testing/dart/compositing_test.dart b/testing/dart/compositing_test.dart index 03f5fbd706da2..c5113d14cf20d 100644 --- a/testing/dart/compositing_test.dart +++ b/testing/dart/compositing_test.dart @@ -83,7 +83,6 @@ void main() { } final Scene scene = builder.build(); - expect(scene != null, true); scene.dispose(); }); diff --git a/testing/dart/mask_filter_test.dart b/testing/dart/mask_filter_test.dart index 7ac3a7c8bce57..f1cd3a1ba5787 100644 --- a/testing/dart/mask_filter_test.dart +++ b/testing/dart/mask_filter_test.dart @@ -22,7 +22,6 @@ void main() { builder.addPicture(Offset.zero, picture); final Scene scene = builder.build(); - expect(scene != null, true); await scene.toImage(100, 100); }); } diff --git a/testing/scenario_app/lib/main.dart b/testing/scenario_app/lib/main.dart index a7a457be6524c..6650eba31489d 100644 --- a/testing/scenario_app/lib/main.dart +++ b/testing/scenario_app/lib/main.dart @@ -12,7 +12,6 @@ import 'dart:ui'; import 'src/scenarios.dart'; void main() { - assert(window.locale != null); window ..onPlatformMessage = _handlePlatformMessage ..onBeginFrame = _onBeginFrame diff --git a/testing/scenario_app/lib/src/animated_color_square.dart b/testing/scenario_app/lib/src/animated_color_square.dart index d1459038fd635..24afd96224f4e 100644 --- a/testing/scenario_app/lib/src/animated_color_square.dart +++ b/testing/scenario_app/lib/src/animated_color_square.dart @@ -17,8 +17,7 @@ class AnimatedColorSquareScenario extends Scenario { /// /// The [dispatcher] parameter must not be null. AnimatedColorSquareScenario(PlatformDispatcher dispatcher) - : assert(dispatcher != null), - super(dispatcher); + : super(dispatcher); static const double _squareSize = 200; /// Used to animate the red value in the color of the square. @@ -77,9 +76,7 @@ class AnimatedColorSquareScenario extends Scenario { class _NumberSwinger { _NumberSwinger(this._begin, this._end, [T? current]) - : assert(_begin != null), - assert(_end != null), - _up = _begin < _end { + : _up = _begin < _end { _current = current ?? _begin; } diff --git a/testing/scenario_app/lib/src/bogus_font_text.dart b/testing/scenario_app/lib/src/bogus_font_text.dart index 1f5745c4fb49c..cee63ce7b9e45 100644 --- a/testing/scenario_app/lib/src/bogus_font_text.dart +++ b/testing/scenario_app/lib/src/bogus_font_text.dart @@ -14,8 +14,7 @@ class BogusFontText extends Scenario { /// /// The [dispatcher] parameter must not be null. BogusFontText(PlatformDispatcher dispatcher) - : assert(dispatcher != null), - super(dispatcher); + : super(dispatcher); // Semi-arbitrary. final double _screenWidth = 700; diff --git a/testing/scenario_app/lib/src/initial_route_reply.dart b/testing/scenario_app/lib/src/initial_route_reply.dart index 7395a7f93c8a4..171ab998e3810 100644 --- a/testing/scenario_app/lib/src/initial_route_reply.dart +++ b/testing/scenario_app/lib/src/initial_route_reply.dart @@ -14,8 +14,7 @@ class InitialRouteReply extends Scenario { /// /// The [window] parameter must not be null. InitialRouteReply(PlatformDispatcher dispatcher) - : assert(dispatcher != null), - super(dispatcher); + : super(dispatcher); @override void onBeginFrame(Duration duration) { diff --git a/testing/scenario_app/lib/src/locale_initialization.dart b/testing/scenario_app/lib/src/locale_initialization.dart index 2cdfc43f24737..93f6d2af3af61 100644 --- a/testing/scenario_app/lib/src/locale_initialization.dart +++ b/testing/scenario_app/lib/src/locale_initialization.dart @@ -13,8 +13,7 @@ import 'scenario.dart'; class LocaleInitialization extends Scenario { /// Constructor LocaleInitialization(PlatformDispatcher dispatcher) - : assert(dispatcher != null), - super(dispatcher); + : super(dispatcher); int _tapCount = 0; diff --git a/testing/scenario_app/lib/src/platform_view.dart b/testing/scenario_app/lib/src/platform_view.dart index 918d59f9fec11..96384f1079bd3 100644 --- a/testing/scenario_app/lib/src/platform_view.dart +++ b/testing/scenario_app/lib/src/platform_view.dart @@ -44,8 +44,7 @@ class PlatformViewScenario extends Scenario PlatformViewScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -71,8 +70,7 @@ class NonFullScreenFlutterViewPlatformViewScenario extends Scenario NonFullScreenFlutterViewPlatformViewScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -98,8 +96,7 @@ class PlatformViewNoOverlayIntersectionScenario extends Scenario PlatformViewNoOverlayIntersectionScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -133,8 +130,7 @@ class PlatformViewLargerThanDisplaySize extends Scenario PlatformViewLargerThanDisplaySize( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -166,8 +162,7 @@ class PlatformViewPartialIntersectionScenario extends Scenario PlatformViewPartialIntersectionScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier . final int id; @@ -198,8 +193,7 @@ class PlatformViewTwoIntersectingOverlaysScenario extends Scenario PlatformViewTwoIntersectingOverlaysScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -242,8 +236,7 @@ class PlatformViewOneOverlayTwoIntersectingOverlaysScenario extends Scenario PlatformViewOneOverlayTwoIntersectingOverlaysScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -293,8 +286,7 @@ class MultiPlatformViewWithoutOverlaysScenario extends Scenario PlatformDispatcher dispatcher, { required this.firstId, required this.secondId, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier to use for the first platform view. final int firstId; @@ -349,8 +341,7 @@ class PlatformViewMaxOverlaysScenario extends Scenario PlatformViewMaxOverlaysScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -404,8 +395,7 @@ class MultiPlatformViewScenario extends Scenario PlatformDispatcher dispatcher, { required this.firstId, required this.secondId, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier to use for the first platform view. final int firstId; @@ -453,8 +443,7 @@ class MultiPlatformViewBackgroundForegroundScenario extends Scenario PlatformDispatcher dispatcher, { required this.firstId, required this.secondId, - }) : assert(dispatcher != null), - super(dispatcher) { + }) : super(dispatcher) { _nextFrame = _firstFrame; } @@ -564,8 +553,7 @@ class PlatformViewClipRectScenario extends Scenario with _BasePlatformViewScenar PlatformViewClipRectScenario( PlatformDispatcher dispatcher, { required this.id, - }) : assert(dispatcher != null), - super(dispatcher); + }) : super(dispatcher); /// The platform view identifier. final int id; @@ -913,8 +901,7 @@ class PlatformViewForTouchIOSScenario extends Scenario this.id = 0, this.rejectUntilTouchesEnded = false, required this.accept, - }) : assert(dispatcher != null), - super(dispatcher) { + }) : super(dispatcher) { _nextFrame = _firstFrame; } @@ -1222,7 +1209,6 @@ class PlatformViewScrollingUnderWidget extends Scenario required int lastPlatformViewId, }) : _firstPlatformViewId = firstPlatformViewId, _lastPlatformViewId = lastPlatformViewId, - assert(dispatcher != null), super(dispatcher); final int _firstPlatformViewId; diff --git a/testing/scenario_app/lib/src/poppable_screen.dart b/testing/scenario_app/lib/src/poppable_screen.dart index 65c94394df486..6e6b7f7f79633 100644 --- a/testing/scenario_app/lib/src/poppable_screen.dart +++ b/testing/scenario_app/lib/src/poppable_screen.dart @@ -15,8 +15,7 @@ class PoppableScreenScenario extends Scenario with PlatformEchoMixin { /// /// The [dispatcher] parameter must not be null. PoppableScreenScenario(PlatformDispatcher dispatcher) - : assert(dispatcher != null), - super(dispatcher); + : super(dispatcher); // Rect for the pop button. Only defined once onMetricsChanged is called. Rect? _buttonRect; diff --git a/tools/licenses/lib/licenses.dart b/tools/licenses/lib/licenses.dart index 2246675e482cb..086fdd44d4f14 100644 --- a/tools/licenses/lib/licenses.dart +++ b/tools/licenses/lib/licenses.dart @@ -340,7 +340,6 @@ abstract class License { body = reformat(body); } final License result; - assert(type != null); switch (type) { case LicenseType.bsd: case LicenseType.mit: @@ -1036,7 +1035,6 @@ Iterable<_LicenseMatch> _tryInline(String body, RegExp pattern, { required bool needsCopyright, required String origin, }) sync* { - assert(needsCopyright != null); for (final _PartialLicenseMatch match in _findLicenseBlocks(body, pattern, 1, 2, needsCopyright: needsCopyright)) { yield _LicenseMatch(License.fromBody(match.getEntireLicense(), origin: origin), match.start, match.end, debug: '_tryInline', missingCopyrights: needsCopyright && !match.hasCopyrights); } @@ -1181,7 +1179,7 @@ License? interpretAsRedirectLicense(String fileContents, LicenseSource parentDir final Match? match = pattern.pattern!.matchAsPrefix(body); if (match != null && match.start == 0 && match.end == body.length) { final License candidate = _dereferenceLicense(3, match.group as String? Function(int?), pattern, parentDirectory, origin: origin); - if (result != null && candidate != null) { + if (result != null) { throw 'Multiple potential matches in interpretAsRedirectLicense in $parentDirectory; body was:\n------8<------\n$fileContents\n------8<------'; } result = candidate; diff --git a/tools/licenses/lib/main.dart b/tools/licenses/lib/main.dart index c3f5f3161f34a..192a175086c2e 100644 --- a/tools/licenses/lib/main.dart +++ b/tools/licenses/lib/main.dart @@ -98,7 +98,7 @@ class _RepositorySourceFile extends _RepositoryLicensedFile { @override Iterable assignLicenses() { _internalLicenses ??= determineLicensesFor(_contents, name, parent, origin: io.fullName); - final List licenses = _internalLicenses!; + final List? licenses = _internalLicenses; if (licenses != null && licenses.isNotEmpty) { return licenses.map((License license) => license.assignLicenses(io.fullName, parent!)); } @@ -964,7 +964,6 @@ class _RepositoryDirectory extends _RepositoryEntry implements LicenseSource { } else if (entry is fs.File) { try { final _RepositoryFile child = createFile(entry); - assert(child != null); if (child is _RepositoryLicensedFile) { _files.add(child); } else { @@ -1080,11 +1079,7 @@ class _RepositoryDirectory extends _RepositoryEntry implements LicenseSource { return const []; } return _licenses.expand((_RepositoryLicenseFile license) { - final List licenses = license.licensesFor(name); - if (licenses != null) { - return licenses; - } - return const []; + return license.licensesFor(name); }).toList(); } @@ -1841,7 +1836,6 @@ class _Progress { } void advance({required bool success}) { - assert(success != null); if (success) { _withLicense += 1; } else { @@ -1904,9 +1898,7 @@ String? _readSignature(String goldenPath) { /// Writes a signature to an [system.IOSink] in the expected format. void _writeSignature(String signature, system.IOSink sink) { - if (signature != null) { - sink.writeln('Signature: $signature\n'); - } + sink.writeln('Signature: $signature\n'); } // Checks for changes to the license tool itself. diff --git a/web_sdk/sdk_rewriter.dart b/web_sdk/sdk_rewriter.dart index e1b1e04024827..4a11ed1940eb6 100644 --- a/web_sdk/sdk_rewriter.dart +++ b/web_sdk/sdk_rewriter.dart @@ -111,7 +111,7 @@ void main(List arguments) { if (results['ui'] as bool) { replacementPatterns = uiPatterns; } else { - libraryName = results['library-name'] as String; + libraryName = results['library-name'] as String?; if (libraryName == null) { throw Exception('library-name must be specified if not rewriting ui'); }