Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2e7d6fa

Browse files
authored
Remove unnecessary null checks (#39113)
1 parent 7b72038 commit 2e7d6fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+109
-563
lines changed

analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ analyzer:
1212
# allow self-reference to deprecated members (we do this because otherwise we have
1313
# to annotate every member in every test, assert, etc, when we deprecate something)
1414
deprecated_member_use_from_same_package: ignore
15-
# Turned off until null-safe rollout is complete.
16-
unnecessary_null_comparison: ignore
1715
exclude: # DIFFERENT FROM FLUTTER/FLUTTER
1816
# Fixture depends on dart:ui and raises false positives.
1917
- flutter_frontend_server/test/fixtures/lib/main.dart

ci/licenses_golden/tool_signature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Signature: 974dd21be7c0e97f436f3758b6de4cee
1+
Signature: ccf8317fb6539998c8f4ff0a96d7f698
22

lib/ui/compositing.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
375375
Clip clipBehavior = Clip.antiAlias,
376376
ClipRectEngineLayer? oldLayer,
377377
}) {
378-
assert(clipBehavior != null);
379378
assert(clipBehavior != Clip.none);
380379
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRect'));
381380
final EngineLayer engineLayer = EngineLayer._();
@@ -411,7 +410,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
411410
Clip clipBehavior = Clip.antiAlias,
412411
ClipRRectEngineLayer? oldLayer,
413412
}) {
414-
assert(clipBehavior != null);
415413
assert(clipBehavior != Clip.none);
416414
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRRect'));
417415
final EngineLayer engineLayer = EngineLayer._();
@@ -439,7 +437,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
439437
Clip clipBehavior = Clip.antiAlias,
440438
ClipPathEngineLayer? oldLayer,
441439
}) {
442-
assert(clipBehavior != null);
443440
assert(clipBehavior != Clip.none);
444441
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipPath'));
445442
final EngineLayer engineLayer = EngineLayer._();
@@ -494,10 +491,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
494491
ColorFilter filter, {
495492
ColorFilterEngineLayer? oldLayer,
496493
}) {
497-
assert(filter != null);
498494
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushColorFilter'));
499495
final _ColorFilter nativeFilter = filter._toNativeColorFilter()!;
500-
assert(nativeFilter != null);
501496
final EngineLayer engineLayer = EngineLayer._();
502497
_pushColorFilter(engineLayer, nativeFilter, oldLayer?._nativeLayer);
503498
final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(engineLayer);
@@ -523,10 +518,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
523518
Offset offset = Offset.zero,
524519
ImageFilterEngineLayer? oldLayer,
525520
}) {
526-
assert(filter != null);
527521
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushImageFilter'));
528522
final _ImageFilter nativeFilter = filter._toNativeImageFilter();
529-
assert(nativeFilter != null);
530523
final EngineLayer engineLayer = EngineLayer._();
531524
_pushImageFilter(engineLayer, nativeFilter, offset.dx, offset.dy, oldLayer?._nativeLayer);
532525
final ImageFilterEngineLayer layer = ImageFilterEngineLayer._(engineLayer);
@@ -799,7 +792,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
799792
bool freeze = false,
800793
FilterQuality filterQuality = FilterQuality.low,
801794
}) {
802-
assert(offset != null, 'Offset argument was null');
803795
_addTexture(offset.dx, offset.dy, width, height, textureId, freeze, filterQuality.index);
804796
}
805797

@@ -828,7 +820,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
828820
double width = 0.0,
829821
double height = 0.0,
830822
}) {
831-
assert(offset != null, 'Offset argument was null');
832823
_addPlatformView(offset.dx, offset.dy, width, height, viewId);
833824
}
834825

lib/ui/experiments/scene.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ class SceneNode extends NativeFieldWrapperClass1 {
8080
<String, WeakReference<SceneNodeValue>>{};
8181

8282
static Future<void> _reinitializeScene(String assetKey) async {
83-
final WeakReference<SceneNodeValue>? sceneRef = _ipsceneRegistry == null
84-
? null
85-
: _ipsceneRegistry[assetKey];
83+
final WeakReference<SceneNodeValue>? sceneRef = _ipsceneRegistry[assetKey];
8684

8785
// If a scene for the asset isn't already registered, then there's no
8886
// need to reinitialize it.

lib/ui/geometry.dart

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ abstract class OffsetBase {
1212
///
1313
/// The first argument sets the horizontal component, and the second the
1414
/// vertical component.
15-
const OffsetBase(this._dx, this._dy)
16-
: assert(_dx != null),
17-
assert(_dy != null);
15+
const OffsetBase(this._dx, this._dy);
1816

1917
final double _dx;
2018
final double _dy;
@@ -314,7 +312,6 @@ class Offset extends OffsetBase {
314312
/// Values for `t` are usually obtained from an [Animation<double>], such as
315313
/// an [AnimationController].
316314
static Offset? lerp(Offset? a, Offset? b, double t) {
317-
assert(t != null);
318315
if (b == null) {
319316
if (a == null) {
320317
return null;
@@ -590,7 +587,6 @@ class Size extends OffsetBase {
590587
/// Values for `t` are usually obtained from an [Animation<double>], such as
591588
/// an [AnimationController].
592589
static Size? lerp(Size? a, Size? b, double t) {
593-
assert(t != null);
594590
if (b == null) {
595591
if (a == null) {
596592
return null;
@@ -637,11 +633,7 @@ class Rect {
637633
/// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb.png#gh-light-mode-only)
638634
/// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb_dark.png#gh-dark-mode-only)
639635
@pragma('vm:entry-point')
640-
const Rect.fromLTRB(this.left, this.top, this.right, this.bottom)
641-
: assert(left != null),
642-
assert(top != null),
643-
assert(right != null),
644-
assert(bottom != null);
636+
const Rect.fromLTRB(this.left, this.top, this.right, this.bottom);
645637

646638
/// Construct a rectangle from its left and top edges, its width, and its
647639
/// height.
@@ -891,7 +883,6 @@ class Rect {
891883
/// Values for `t` are usually obtained from an [Animation<double>], such as
892884
/// an [AnimationController].
893885
static Rect? lerp(Rect? a, Rect? b, double t) {
894-
assert(t != null);
895886
if (b == null) {
896887
if (a == null) {
897888
return null;
@@ -1059,7 +1050,6 @@ class Radius {
10591050
/// Values for `t` are usually obtained from an [Animation<double>], such as
10601051
/// an [AnimationController].
10611052
static Radius? lerp(Radius? a, Radius? b, double t) {
1062-
assert(t != null);
10631053
if (b == null) {
10641054
if (a == null) {
10651055
return null;
@@ -1268,19 +1258,7 @@ class RRect {
12681258
this.brRadiusY = 0.0,
12691259
this.blRadiusX = 0.0,
12701260
this.blRadiusY = 0.0,
1271-
}) : assert(left != null),
1272-
assert(top != null),
1273-
assert(right != null),
1274-
assert(bottom != null),
1275-
assert(tlRadiusX != null),
1276-
assert(tlRadiusY != null),
1277-
assert(trRadiusX != null),
1278-
assert(trRadiusY != null),
1279-
assert(brRadiusX != null),
1280-
assert(brRadiusY != null),
1281-
assert(blRadiusX != null),
1282-
assert(blRadiusY != null),
1283-
assert(tlRadiusX >= 0),
1261+
}) : assert(tlRadiusX >= 0),
12841262
assert(tlRadiusY >= 0),
12851263
assert(trRadiusX >= 0),
12861264
assert(trRadiusY >= 0),
@@ -1661,7 +1639,6 @@ class RRect {
16611639
/// Values for `t` are usually obtained from an [Animation<double>], such as
16621640
/// an [AnimationController].
16631641
static RRect? lerp(RRect? a, RRect? b, double t) {
1664-
assert(t != null);
16651642
if (b == null) {
16661643
if (a == null) {
16671644
return null;

lib/ui/hooks.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ void _invoke(void Function()? callback, Zone zone) {
138138
if (callback == null) {
139139
return;
140140
}
141-
142-
assert(zone != null);
143-
144141
if (identical(zone, Zone.current)) {
145142
callback();
146143
} else {
@@ -157,9 +154,6 @@ void _invoke1<A>(void Function(A a)? callback, Zone zone, A arg) {
157154
if (callback == null) {
158155
return;
159156
}
160-
161-
assert(zone != null);
162-
163157
if (identical(zone, Zone.current)) {
164158
callback(arg);
165159
} else {
@@ -176,9 +170,6 @@ void _invoke2<A1, A2>(void Function(A1 a1, A2 a2)? callback, Zone zone, A1 arg1,
176170
if (callback == null) {
177171
return;
178172
}
179-
180-
assert(zone != null);
181-
182173
if (identical(zone, Zone.current)) {
183174
callback(arg1, arg2);
184175
} else {
@@ -197,9 +188,6 @@ void _invoke3<A1, A2, A3>(void Function(A1 a1, A2 a2, A3 a3)? callback, Zone zon
197188
if (callback == null) {
198189
return;
199190
}
200-
201-
assert(zone != null);
202-
203191
if (identical(zone, Zone.current)) {
204192
callback(arg1, arg2, arg3);
205193
} else {

lib/ui/isolate_name_server.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class IsolateNameServer {
3131
///
3232
/// The `name` argument must not be null.
3333
static SendPort? lookupPortByName(String name) {
34-
assert(name != null, "'name' cannot be null.");
3534
return _lookupPortByName(name);
3635
}
3736

@@ -49,8 +48,6 @@ class IsolateNameServer {
4948
///
5049
/// The `port` and `name` arguments must not be null.
5150
static bool registerPortWithName(SendPort port, String name) {
52-
assert(port != null, "'port' cannot be null.");
53-
assert(name != null, "'name' cannot be null.");
5451
return _registerPortWithName(port, name);
5552
}
5653

@@ -66,7 +63,6 @@ class IsolateNameServer {
6663
///
6764
/// The `name` argument must not be null.
6865
static bool removePortNameMapping(String name) {
69-
assert(name != null, "'name' cannot be null.");
7066
return _removePortNameMapping(name);
7167
}
7268

0 commit comments

Comments
 (0)