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

Commit 5d74b5c

Browse files
authored
Remove unnecessary null checks in flutter/painting (#118925)
1 parent c757df3 commit 5d74b5c

36 files changed

+56
-315
lines changed

packages/flutter/lib/src/painting/_network_image_io.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
1919
/// Creates an object that fetches the image at the given URL.
2020
///
2121
/// The arguments [url] and [scale] must not be null.
22-
const NetworkImage(this.url, { this.scale = 1.0, this.headers })
23-
: assert(url != null),
24-
assert(scale != null);
22+
const NetworkImage(this.url, { this.scale = 1.0, this.headers });
2523

2624
@override
2725
final String url;

packages/flutter/lib/src/painting/_network_image_web.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ class NetworkImage
3939
/// Creates an object that fetches the image at the given URL.
4040
///
4141
/// The arguments [url] and [scale] must not be null.
42-
const NetworkImage(this.url, {this.scale = 1.0, this.headers})
43-
: assert(url != null),
44-
assert(scale != null);
42+
const NetworkImage(this.url, {this.scale = 1.0, this.headers});
4543

4644
@override
4745
final String url;

packages/flutter/lib/src/painting/alignment.dart

+3-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ abstract class AlignmentGeometry {
8787
///
8888
/// {@macro dart.ui.shadow.lerp}
8989
static AlignmentGeometry? lerp(AlignmentGeometry? a, AlignmentGeometry? b, double t) {
90-
assert(t != null);
9190
if (a == null && b == null) {
9291
return null;
9392
}
@@ -188,9 +187,7 @@ class Alignment extends AlignmentGeometry {
188187
/// Creates an alignment.
189188
///
190189
/// The [x] and [y] arguments must not be null.
191-
const Alignment(this.x, this.y)
192-
: assert(x != null),
193-
assert(y != null);
190+
const Alignment(this.x, this.y);
194191

195192
/// The distance fraction in the horizontal direction.
196193
///
@@ -340,7 +337,6 @@ class Alignment extends AlignmentGeometry {
340337
///
341338
/// {@macro dart.ui.shadow.lerp}
342339
static Alignment? lerp(Alignment? a, Alignment? b, double t) {
343-
assert(t != null);
344340
if (a == null && b == null) {
345341
return null;
346342
}
@@ -407,9 +403,7 @@ class AlignmentDirectional extends AlignmentGeometry {
407403
/// Creates a directional alignment.
408404
///
409405
/// The [start] and [y] arguments must not be null.
410-
const AlignmentDirectional(this.start, this.y)
411-
: assert(start != null),
412-
assert(y != null);
406+
const AlignmentDirectional(this.start, this.y);
413407

414408
/// The distance fraction in the horizontal direction.
415409
///
@@ -534,7 +528,6 @@ class AlignmentDirectional extends AlignmentGeometry {
534528
///
535529
/// {@macro dart.ui.shadow.lerp}
536530
static AlignmentDirectional? lerp(AlignmentDirectional? a, AlignmentDirectional? b, double t) {
537-
assert(t != null);
538531
if (a == null && b == null) {
539532
return null;
540533
}
@@ -682,8 +675,7 @@ class TextAlignVertical {
682675
/// Creates a TextAlignVertical from any y value between -1.0 and 1.0.
683676
const TextAlignVertical({
684677
required this.y,
685-
}) : assert(y != null),
686-
assert(y >= -1.0 && y <= 1.0);
678+
}) : assert(y >= -1.0 && y <= 1.0);
687679

688680
/// A value ranging from -1.0 to 1.0 that defines the topmost and bottommost
689681
/// locations of the top and bottom of the input box.

packages/flutter/lib/src/painting/basic_types.dart

-5
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ enum Axis {
136136
///
137137
/// * [flipAxisDirection], which does the same thing for [AxisDirection] values.
138138
Axis flipAxis(Axis direction) {
139-
assert(direction != null);
140139
switch (direction) {
141140
case Axis.horizontal:
142141
return Axis.vertical;
@@ -204,7 +203,6 @@ enum AxisDirection {
204203
/// [AxisDirection.down] and returns [Axis.horizontal] for [AxisDirection.left]
205204
/// and [AxisDirection.right].
206205
Axis axisDirectionToAxis(AxisDirection axisDirection) {
207-
assert(axisDirection != null);
208206
switch (axisDirection) {
209207
case AxisDirection.up:
210208
case AxisDirection.down:
@@ -220,7 +218,6 @@ Axis axisDirectionToAxis(AxisDirection axisDirection) {
220218
/// Specifically, returns [AxisDirection.left] for [TextDirection.rtl] and
221219
/// [AxisDirection.right] for [TextDirection.ltr].
222220
AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
223-
assert(textDirection != null);
224221
switch (textDirection) {
225222
case TextDirection.rtl:
226223
return AxisDirection.left;
@@ -239,7 +236,6 @@ AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
239236
///
240237
/// * [flipAxis], which does the same thing for [Axis] values.
241238
AxisDirection flipAxisDirection(AxisDirection axisDirection) {
242-
assert(axisDirection != null);
243239
switch (axisDirection) {
244240
case AxisDirection.up:
245241
return AxisDirection.down;
@@ -258,7 +254,6 @@ AxisDirection flipAxisDirection(AxisDirection axisDirection) {
258254
/// Specifically, returns true for [AxisDirection.up] and [AxisDirection.left]
259255
/// and false for [AxisDirection.down] and [AxisDirection.right].
260256
bool axisDirectionIsReversed(AxisDirection axisDirection) {
261-
assert(axisDirection != null);
262257
switch (axisDirection) {
263258
case AxisDirection.up:
264259
case AxisDirection.left:

packages/flutter/lib/src/painting/beveled_rectangle_border.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class BeveledRectangleBorder extends OutlinedBorder {
2525
const BeveledRectangleBorder({
2626
super.side,
2727
this.borderRadius = BorderRadius.zero,
28-
}) : assert(side != null),
29-
assert(borderRadius != null);
28+
});
3029

3130
/// The radii for each corner.
3231
///
@@ -49,7 +48,6 @@ class BeveledRectangleBorder extends OutlinedBorder {
4948

5049
@override
5150
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
52-
assert(t != null);
5351
if (a is BeveledRectangleBorder) {
5452
return BeveledRectangleBorder(
5553
side: BorderSide.lerp(a.side, side, t),
@@ -61,7 +59,6 @@ class BeveledRectangleBorder extends OutlinedBorder {
6159

6260
@override
6361
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
64-
assert(t != null);
6562
if (b is BeveledRectangleBorder) {
6663
return BeveledRectangleBorder(
6764
side: BorderSide.lerp(side, b.side, t),

packages/flutter/lib/src/painting/binding.dart

-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
111111
}) {
112112
assert(cacheWidth == null || cacheWidth > 0);
113113
assert(cacheHeight == null || cacheHeight > 0);
114-
assert(allowUpscaling != null);
115114
return ui.instantiateImageCodec(
116115
bytes,
117116
targetWidth: cacheWidth,
@@ -149,7 +148,6 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
149148
}) {
150149
assert(cacheWidth == null || cacheWidth > 0);
151150
assert(cacheHeight == null || cacheHeight > 0);
152-
assert(allowUpscaling != null);
153151
return ui.instantiateImageCodecFromBuffer(
154152
buffer,
155153
targetWidth: cacheWidth,

packages/flutter/lib/src/painting/border_radius.dart

-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ abstract class BorderRadiusGeometry {
129129
///
130130
/// {@macro dart.ui.shadow.lerp}
131131
static BorderRadiusGeometry? lerp(BorderRadiusGeometry? a, BorderRadiusGeometry? b, double t) {
132-
assert(t != null);
133132
if (a == null && b == null) {
134133
return null;
135134
}
@@ -507,7 +506,6 @@ class BorderRadius extends BorderRadiusGeometry {
507506
///
508507
/// {@macro dart.ui.shadow.lerp}
509508
static BorderRadius? lerp(BorderRadius? a, BorderRadius? b, double t) {
510-
assert(t != null);
511509
if (a == null && b == null) {
512510
return null;
513511
}
@@ -729,7 +727,6 @@ class BorderRadiusDirectional extends BorderRadiusGeometry {
729727
///
730728
/// {@macro dart.ui.shadow.lerp}
731729
static BorderRadiusDirectional? lerp(BorderRadiusDirectional? a, BorderRadiusDirectional? b, double t) {
732-
assert(t != null);
733730
if (a == null && b == null) {
734731
return null;
735732
}

packages/flutter/lib/src/painting/borders.dart

+3-25
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ class BorderSide with Diagnosticable {
6666
this.width = 1.0,
6767
this.style = BorderStyle.solid,
6868
this.strokeAlign = strokeAlignInside,
69-
}) : assert(color != null),
70-
assert(width != null),
71-
assert(width >= 0.0),
72-
assert(style != null),
73-
assert(strokeAlign != null);
69+
}) : assert(width >= 0.0);
7470

7571
/// Creates a [BorderSide] that represents the addition of the two given
7672
/// [BorderSide]s.
@@ -84,8 +80,6 @@ class BorderSide with Diagnosticable {
8480
///
8581
/// The arguments must not be null.
8682
static BorderSide merge(BorderSide a, BorderSide b) {
87-
assert(a != null);
88-
assert(b != null);
8983
assert(canMerge(a, b));
9084
final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0;
9185
final bool bIsNone = b.style == BorderStyle.none && b.width == 0.0;
@@ -202,7 +196,6 @@ class BorderSide with Diagnosticable {
202196
/// Values for `t` are usually obtained from an [Animation<double>], such as
203197
/// an [AnimationController].
204198
BorderSide scale(double t) {
205-
assert(t != null);
206199
return BorderSide(
207200
color: color,
208201
width: math.max(0.0, width * t),
@@ -239,8 +232,6 @@ class BorderSide with Diagnosticable {
239232
///
240233
/// The arguments must not be null.
241234
static bool canMerge(BorderSide a, BorderSide b) {
242-
assert(a != null);
243-
assert(b != null);
244235
if ((a.style == BorderStyle.none && a.width == 0.0) ||
245236
(b.style == BorderStyle.none && b.width == 0.0)) {
246237
return true;
@@ -255,9 +246,6 @@ class BorderSide with Diagnosticable {
255246
///
256247
/// {@macro dart.ui.shadow.lerp}
257248
static BorderSide lerp(BorderSide a, BorderSide b, double t) {
258-
assert(a != null);
259-
assert(b != null);
260-
assert(t != null);
261249
if (t == 0.0) {
262250
return a;
263251
}
@@ -517,7 +505,6 @@ abstract class ShapeBorder {
517505
///
518506
/// {@macro dart.ui.shadow.lerp}
519507
static ShapeBorder? lerp(ShapeBorder? a, ShapeBorder? b, double t) {
520-
assert(t != null);
521508
ShapeBorder? result;
522509
if (b != null) {
523510
result = b.lerpFrom(a, t);
@@ -664,7 +651,7 @@ abstract class OutlinedBorder extends ShapeBorder {
664651
/// const constructors so that they can be used in const expressions.
665652
///
666653
/// The value of [side] must not be null.
667-
const OutlinedBorder({ this.side = BorderSide.none }) : assert(side != null);
654+
const OutlinedBorder({ this.side = BorderSide.none });
668655

669656
@override
670657
EdgeInsetsGeometry get dimensions => EdgeInsets.all(math.max(side.strokeInset, 0));
@@ -707,7 +694,6 @@ abstract class OutlinedBorder extends ShapeBorder {
707694
///
708695
/// {@macro dart.ui.shadow.lerp}
709696
static OutlinedBorder? lerp(OutlinedBorder? a, OutlinedBorder? b, double t) {
710-
assert(t != null);
711697
ShapeBorder? result;
712698
if (b != null) {
713699
result = b.lerpFrom(a, t);
@@ -724,8 +710,7 @@ abstract class OutlinedBorder extends ShapeBorder {
724710
/// The borders are listed from the outside to the inside.
725711
class _CompoundBorder extends ShapeBorder {
726712
_CompoundBorder(this.borders)
727-
: assert(borders != null),
728-
assert(borders.length >= 2),
713+
: assert(borders.length >= 2),
729714
assert(!borders.any((ShapeBorder border) => border is _CompoundBorder));
730715

731716
final List<ShapeBorder> borders;
@@ -788,7 +773,6 @@ class _CompoundBorder extends ShapeBorder {
788773
}
789774

790775
static _CompoundBorder lerp(ShapeBorder? a, ShapeBorder? b, double t) {
791-
assert(t != null);
792776
assert(a is _CompoundBorder || b is _CompoundBorder); // Not really necessary, but all call sites currently intend this.
793777
final List<ShapeBorder?> aList = a is _CompoundBorder ? a.borders : <ShapeBorder?>[a];
794778
final List<ShapeBorder?> bList = b is _CompoundBorder ? b.borders : <ShapeBorder?>[b];
@@ -897,12 +881,6 @@ void paintBorder(
897881
BorderSide bottom = BorderSide.none,
898882
BorderSide left = BorderSide.none,
899883
}) {
900-
assert(canvas != null);
901-
assert(rect != null);
902-
assert(top != null);
903-
assert(right != null);
904-
assert(bottom != null);
905-
assert(left != null);
906884

907885
// We draw the borders as filled shapes, unless the borders are hairline
908886
// borders, in which case we use PaintingStyle.stroke, with the stroke width

packages/flutter/lib/src/painting/box_border.dart

+4-20
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ abstract class BoxBorder extends ShapeBorder {
103103
///
104104
/// {@macro dart.ui.shadow.lerp}
105105
static BoxBorder? lerp(BoxBorder? a, BoxBorder? b, double t) {
106-
assert(t != null);
107106
if ((a is Border?) && (b is Border?)) {
108107
return Border.lerp(a, b, t);
109108
}
@@ -322,17 +321,13 @@ class Border extends BoxBorder {
322321
this.right = BorderSide.none,
323322
this.bottom = BorderSide.none,
324323
this.left = BorderSide.none,
325-
}) : assert(top != null),
326-
assert(right != null),
327-
assert(bottom != null),
328-
assert(left != null);
324+
});
329325

330326
/// Creates a border whose sides are all the same.
331327
///
332328
/// The `side` argument must not be null.
333329
const Border.fromBorderSide(BorderSide side)
334-
: assert(side != null),
335-
top = side,
330+
: top = side,
336331
right = side,
337332
bottom = side,
338333
left = side;
@@ -346,9 +341,7 @@ class Border extends BoxBorder {
346341
const Border.symmetric({
347342
BorderSide vertical = BorderSide.none,
348343
BorderSide horizontal = BorderSide.none,
349-
}) : assert(vertical != null),
350-
assert(horizontal != null),
351-
left = vertical,
344+
}) : left = vertical,
352345
top = horizontal,
353346
right = vertical,
354347
bottom = horizontal;
@@ -374,8 +367,6 @@ class Border extends BoxBorder {
374367
///
375368
/// The arguments must not be null.
376369
static Border merge(Border a, Border b) {
377-
assert(a != null);
378-
assert(b != null);
379370
assert(BorderSide.canMerge(a.top, b.top));
380371
assert(BorderSide.canMerge(a.right, b.right));
381372
assert(BorderSide.canMerge(a.bottom, b.bottom));
@@ -478,7 +469,6 @@ class Border extends BoxBorder {
478469
///
479470
/// {@macro dart.ui.shadow.lerp}
480471
static Border? lerp(Border? a, Border? b, double t) {
481-
assert(t != null);
482472
if (a == null && b == null) {
483473
return null;
484474
}
@@ -650,10 +640,7 @@ class BorderDirectional extends BoxBorder {
650640
this.start = BorderSide.none,
651641
this.end = BorderSide.none,
652642
this.bottom = BorderSide.none,
653-
}) : assert(top != null),
654-
assert(start != null),
655-
assert(end != null),
656-
assert(bottom != null);
643+
});
657644

658645
/// Creates a [BorderDirectional] that represents the addition of the two
659646
/// given [BorderDirectional]s.
@@ -663,8 +650,6 @@ class BorderDirectional extends BoxBorder {
663650
///
664651
/// The arguments must not be null.
665652
static BorderDirectional merge(BorderDirectional a, BorderDirectional b) {
666-
assert(a != null);
667-
assert(b != null);
668653
assert(BorderSide.canMerge(a.top, b.top));
669654
assert(BorderSide.canMerge(a.start, b.start));
670655
assert(BorderSide.canMerge(a.end, b.end));
@@ -826,7 +811,6 @@ class BorderDirectional extends BoxBorder {
826811
///
827812
/// {@macro dart.ui.shadow.lerp}
828813
static BorderDirectional? lerp(BorderDirectional? a, BorderDirectional? b, double t) {
829-
assert(t != null);
830814
if (a == null && b == null) {
831815
return null;
832816
}

0 commit comments

Comments
 (0)