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

Commit

Permalink
Remove unnecessary null checks in flutter/painting (#118925)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer committed Jan 21, 2023
1 parent c757df3 commit 5d74b5c
Show file tree
Hide file tree
Showing 36 changed files with 56 additions and 315 deletions.
4 changes: 1 addition & 3 deletions packages/flutter/lib/src/painting/_network_image_io.dart
Expand Up @@ -19,9 +19,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
/// Creates an object that fetches the image at the given URL.
///
/// The arguments [url] and [scale] must not be null.
const NetworkImage(this.url, { this.scale = 1.0, this.headers })
: assert(url != null),
assert(scale != null);
const NetworkImage(this.url, { this.scale = 1.0, this.headers });

@override
final String url;
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter/lib/src/painting/_network_image_web.dart
Expand Up @@ -39,9 +39,7 @@ class NetworkImage
/// Creates an object that fetches the image at the given URL.
///
/// The arguments [url] and [scale] must not be null.
const NetworkImage(this.url, {this.scale = 1.0, this.headers})
: assert(url != null),
assert(scale != null);
const NetworkImage(this.url, {this.scale = 1.0, this.headers});

@override
final String url;
Expand Down
14 changes: 3 additions & 11 deletions packages/flutter/lib/src/painting/alignment.dart
Expand Up @@ -87,7 +87,6 @@ abstract class AlignmentGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static AlignmentGeometry? lerp(AlignmentGeometry? a, AlignmentGeometry? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -188,9 +187,7 @@ class Alignment extends AlignmentGeometry {
/// Creates an alignment.
///
/// The [x] and [y] arguments must not be null.
const Alignment(this.x, this.y)
: assert(x != null),
assert(y != null);
const Alignment(this.x, this.y);

/// The distance fraction in the horizontal direction.
///
Expand Down Expand Up @@ -340,7 +337,6 @@ class Alignment extends AlignmentGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static Alignment? lerp(Alignment? a, Alignment? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -407,9 +403,7 @@ class AlignmentDirectional extends AlignmentGeometry {
/// Creates a directional alignment.
///
/// The [start] and [y] arguments must not be null.
const AlignmentDirectional(this.start, this.y)
: assert(start != null),
assert(y != null);
const AlignmentDirectional(this.start, this.y);

/// The distance fraction in the horizontal direction.
///
Expand Down Expand Up @@ -534,7 +528,6 @@ class AlignmentDirectional extends AlignmentGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static AlignmentDirectional? lerp(AlignmentDirectional? a, AlignmentDirectional? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -682,8 +675,7 @@ class TextAlignVertical {
/// Creates a TextAlignVertical from any y value between -1.0 and 1.0.
const TextAlignVertical({
required this.y,
}) : assert(y != null),
assert(y >= -1.0 && y <= 1.0);
}) : assert(y >= -1.0 && y <= 1.0);

/// A value ranging from -1.0 to 1.0 that defines the topmost and bottommost
/// locations of the top and bottom of the input box.
Expand Down
5 changes: 0 additions & 5 deletions packages/flutter/lib/src/painting/basic_types.dart
Expand Up @@ -136,7 +136,6 @@ enum Axis {
///
/// * [flipAxisDirection], which does the same thing for [AxisDirection] values.
Axis flipAxis(Axis direction) {
assert(direction != null);
switch (direction) {
case Axis.horizontal:
return Axis.vertical;
Expand Down Expand Up @@ -204,7 +203,6 @@ enum AxisDirection {
/// [AxisDirection.down] and returns [Axis.horizontal] for [AxisDirection.left]
/// and [AxisDirection.right].
Axis axisDirectionToAxis(AxisDirection axisDirection) {
assert(axisDirection != null);
switch (axisDirection) {
case AxisDirection.up:
case AxisDirection.down:
Expand All @@ -220,7 +218,6 @@ Axis axisDirectionToAxis(AxisDirection axisDirection) {
/// Specifically, returns [AxisDirection.left] for [TextDirection.rtl] and
/// [AxisDirection.right] for [TextDirection.ltr].
AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
assert(textDirection != null);
switch (textDirection) {
case TextDirection.rtl:
return AxisDirection.left;
Expand All @@ -239,7 +236,6 @@ AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
///
/// * [flipAxis], which does the same thing for [Axis] values.
AxisDirection flipAxisDirection(AxisDirection axisDirection) {
assert(axisDirection != null);
switch (axisDirection) {
case AxisDirection.up:
return AxisDirection.down;
Expand All @@ -258,7 +254,6 @@ AxisDirection flipAxisDirection(AxisDirection axisDirection) {
/// Specifically, returns true for [AxisDirection.up] and [AxisDirection.left]
/// and false for [AxisDirection.down] and [AxisDirection.right].
bool axisDirectionIsReversed(AxisDirection axisDirection) {
assert(axisDirection != null);
switch (axisDirection) {
case AxisDirection.up:
case AxisDirection.left:
Expand Down
Expand Up @@ -25,8 +25,7 @@ class BeveledRectangleBorder extends OutlinedBorder {
const BeveledRectangleBorder({
super.side,
this.borderRadius = BorderRadius.zero,
}) : assert(side != null),
assert(borderRadius != null);
});

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

@override
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
assert(t != null);
if (a is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(a.side, side, t),
Expand All @@ -61,7 +59,6 @@ class BeveledRectangleBorder extends OutlinedBorder {

@override
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
assert(t != null);
if (b is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(side, b.side, t),
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/binding.dart
Expand Up @@ -111,7 +111,6 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
}) {
assert(cacheWidth == null || cacheWidth > 0);
assert(cacheHeight == null || cacheHeight > 0);
assert(allowUpscaling != null);
return ui.instantiateImageCodec(
bytes,
targetWidth: cacheWidth,
Expand Down Expand Up @@ -149,7 +148,6 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
}) {
assert(cacheWidth == null || cacheWidth > 0);
assert(cacheHeight == null || cacheHeight > 0);
assert(allowUpscaling != null);
return ui.instantiateImageCodecFromBuffer(
buffer,
targetWidth: cacheWidth,
Expand Down
3 changes: 0 additions & 3 deletions packages/flutter/lib/src/painting/border_radius.dart
Expand Up @@ -129,7 +129,6 @@ abstract class BorderRadiusGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadiusGeometry? lerp(BorderRadiusGeometry? a, BorderRadiusGeometry? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -507,7 +506,6 @@ class BorderRadius extends BorderRadiusGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadius? lerp(BorderRadius? a, BorderRadius? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -729,7 +727,6 @@ class BorderRadiusDirectional extends BorderRadiusGeometry {
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadiusDirectional? lerp(BorderRadiusDirectional? a, BorderRadiusDirectional? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down
28 changes: 3 additions & 25 deletions packages/flutter/lib/src/painting/borders.dart
Expand Up @@ -66,11 +66,7 @@ class BorderSide with Diagnosticable {
this.width = 1.0,
this.style = BorderStyle.solid,
this.strokeAlign = strokeAlignInside,
}) : assert(color != null),
assert(width != null),
assert(width >= 0.0),
assert(style != null),
assert(strokeAlign != null);
}) : assert(width >= 0.0);

/// Creates a [BorderSide] that represents the addition of the two given
/// [BorderSide]s.
Expand All @@ -84,8 +80,6 @@ class BorderSide with Diagnosticable {
///
/// The arguments must not be null.
static BorderSide merge(BorderSide a, BorderSide b) {
assert(a != null);
assert(b != null);
assert(canMerge(a, b));
final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0;
final bool bIsNone = b.style == BorderStyle.none && b.width == 0.0;
Expand Down Expand Up @@ -202,7 +196,6 @@ class BorderSide with Diagnosticable {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
BorderSide scale(double t) {
assert(t != null);
return BorderSide(
color: color,
width: math.max(0.0, width * t),
Expand Down Expand Up @@ -239,8 +232,6 @@ class BorderSide with Diagnosticable {
///
/// The arguments must not be null.
static bool canMerge(BorderSide a, BorderSide b) {
assert(a != null);
assert(b != null);
if ((a.style == BorderStyle.none && a.width == 0.0) ||
(b.style == BorderStyle.none && b.width == 0.0)) {
return true;
Expand All @@ -255,9 +246,6 @@ class BorderSide with Diagnosticable {
///
/// {@macro dart.ui.shadow.lerp}
static BorderSide lerp(BorderSide a, BorderSide b, double t) {
assert(a != null);
assert(b != null);
assert(t != null);
if (t == 0.0) {
return a;
}
Expand Down Expand Up @@ -517,7 +505,6 @@ abstract class ShapeBorder {
///
/// {@macro dart.ui.shadow.lerp}
static ShapeBorder? lerp(ShapeBorder? a, ShapeBorder? b, double t) {
assert(t != null);
ShapeBorder? result;
if (b != null) {
result = b.lerpFrom(a, t);
Expand Down Expand Up @@ -664,7 +651,7 @@ abstract class OutlinedBorder extends ShapeBorder {
/// const constructors so that they can be used in const expressions.
///
/// The value of [side] must not be null.
const OutlinedBorder({ this.side = BorderSide.none }) : assert(side != null);
const OutlinedBorder({ this.side = BorderSide.none });

@override
EdgeInsetsGeometry get dimensions => EdgeInsets.all(math.max(side.strokeInset, 0));
Expand Down Expand Up @@ -707,7 +694,6 @@ abstract class OutlinedBorder extends ShapeBorder {
///
/// {@macro dart.ui.shadow.lerp}
static OutlinedBorder? lerp(OutlinedBorder? a, OutlinedBorder? b, double t) {
assert(t != null);
ShapeBorder? result;
if (b != null) {
result = b.lerpFrom(a, t);
Expand All @@ -724,8 +710,7 @@ abstract class OutlinedBorder extends ShapeBorder {
/// The borders are listed from the outside to the inside.
class _CompoundBorder extends ShapeBorder {
_CompoundBorder(this.borders)
: assert(borders != null),
assert(borders.length >= 2),
: assert(borders.length >= 2),
assert(!borders.any((ShapeBorder border) => border is _CompoundBorder));

final List<ShapeBorder> borders;
Expand Down Expand Up @@ -788,7 +773,6 @@ class _CompoundBorder extends ShapeBorder {
}

static _CompoundBorder lerp(ShapeBorder? a, ShapeBorder? b, double t) {
assert(t != null);
assert(a is _CompoundBorder || b is _CompoundBorder); // Not really necessary, but all call sites currently intend this.
final List<ShapeBorder?> aList = a is _CompoundBorder ? a.borders : <ShapeBorder?>[a];
final List<ShapeBorder?> bList = b is _CompoundBorder ? b.borders : <ShapeBorder?>[b];
Expand Down Expand Up @@ -897,12 +881,6 @@ void paintBorder(
BorderSide bottom = BorderSide.none,
BorderSide left = BorderSide.none,
}) {
assert(canvas != null);
assert(rect != null);
assert(top != null);
assert(right != null);
assert(bottom != null);
assert(left != null);

// We draw the borders as filled shapes, unless the borders are hairline
// borders, in which case we use PaintingStyle.stroke, with the stroke width
Expand Down
24 changes: 4 additions & 20 deletions packages/flutter/lib/src/painting/box_border.dart
Expand Up @@ -103,7 +103,6 @@ abstract class BoxBorder extends ShapeBorder {
///
/// {@macro dart.ui.shadow.lerp}
static BoxBorder? lerp(BoxBorder? a, BoxBorder? b, double t) {
assert(t != null);
if ((a is Border?) && (b is Border?)) {
return Border.lerp(a, b, t);
}
Expand Down Expand Up @@ -322,17 +321,13 @@ class Border extends BoxBorder {
this.right = BorderSide.none,
this.bottom = BorderSide.none,
this.left = BorderSide.none,
}) : assert(top != null),
assert(right != null),
assert(bottom != null),
assert(left != null);
});

/// Creates a border whose sides are all the same.
///
/// The `side` argument must not be null.
const Border.fromBorderSide(BorderSide side)
: assert(side != null),
top = side,
: top = side,
right = side,
bottom = side,
left = side;
Expand All @@ -346,9 +341,7 @@ class Border extends BoxBorder {
const Border.symmetric({
BorderSide vertical = BorderSide.none,
BorderSide horizontal = BorderSide.none,
}) : assert(vertical != null),
assert(horizontal != null),
left = vertical,
}) : left = vertical,
top = horizontal,
right = vertical,
bottom = horizontal;
Expand All @@ -374,8 +367,6 @@ class Border extends BoxBorder {
///
/// The arguments must not be null.
static Border merge(Border a, Border b) {
assert(a != null);
assert(b != null);
assert(BorderSide.canMerge(a.top, b.top));
assert(BorderSide.canMerge(a.right, b.right));
assert(BorderSide.canMerge(a.bottom, b.bottom));
Expand Down Expand Up @@ -478,7 +469,6 @@ class Border extends BoxBorder {
///
/// {@macro dart.ui.shadow.lerp}
static Border? lerp(Border? a, Border? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -650,10 +640,7 @@ class BorderDirectional extends BoxBorder {
this.start = BorderSide.none,
this.end = BorderSide.none,
this.bottom = BorderSide.none,
}) : assert(top != null),
assert(start != null),
assert(end != null),
assert(bottom != null);
});

/// Creates a [BorderDirectional] that represents the addition of the two
/// given [BorderDirectional]s.
Expand All @@ -663,8 +650,6 @@ class BorderDirectional extends BoxBorder {
///
/// The arguments must not be null.
static BorderDirectional merge(BorderDirectional a, BorderDirectional b) {
assert(a != null);
assert(b != null);
assert(BorderSide.canMerge(a.top, b.top));
assert(BorderSide.canMerge(a.start, b.start));
assert(BorderSide.canMerge(a.end, b.end));
Expand Down Expand Up @@ -826,7 +811,6 @@ class BorderDirectional extends BoxBorder {
///
/// {@macro dart.ui.shadow.lerp}
static BorderDirectional? lerp(BorderDirectional? a, BorderDirectional? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down

0 comments on commit 5d74b5c

Please sign in to comment.