Skip to content

Commit fe9a2c5

Browse files
authored
Remove 'must not be null' comments from painting and rendering libraries. (flutter#134993)
## Description This removes all of the comments that are of the form "so-and-so (must not be null|can ?not be null|must be non-null)" from the cases where those values are defines as non-nullable values. This PR removes them from the painting and rendering libraries. This was done by hand, since it really didn't lend itself to scripting, so it needs to be more than just spot-checked, I think. I was careful to leave any comment that referred to parameters that were nullable, but I may have missed some. In addition to being no longer relevant after null safety has been made the default, these comments were largely fragile, in that it was easy for them to get out of date, and not be accurate anymore anyhow. This did create a number of constructor comments which basically say "Creates a [Foo].", but I don't really know how to avoid that in a large scale change, since there's not much you can really say in a lot of cases. I think we might consider some leniency for constructors to the "Comment must be meaningful" style guidance (which we de facto have already, since there are a bunch of these). ## Related PRs - flutter#134984 - flutter#134991 - flutter#134992 - flutter#134994 ## Tests - Documentation only change.
1 parent 14b832a commit fe9a2c5

Some content is hidden

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

59 files changed

+79
-309
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer bu
2020
@immutable
2121
class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkImage> implements image_provider.NetworkImage {
2222
/// Creates an object that fetches the image at the given URL.
23-
///
24-
/// The arguments [url] and [scale] must not be null.
2523
const NetworkImage(this.url, { this.scale = 1.0, this.headers });
2624

2725
@override

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class NetworkImage
4040
extends image_provider.ImageProvider<image_provider.NetworkImage>
4141
implements image_provider.NetworkImage {
4242
/// Creates an object that fetches the image at the given URL.
43-
///
44-
/// The arguments [url] and [scale] must not be null.
4543
const NetworkImage(this.url, {this.scale = 1.0, this.headers});
4644

4745
@override

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ abstract class AlignmentGeometry {
185185
/// whether the horizontal direction depends on the [TextDirection].
186186
class Alignment extends AlignmentGeometry {
187187
/// Creates an alignment.
188-
///
189-
/// The [x] and [y] arguments must not be null.
190188
const Alignment(this.x, this.y);
191189

192190
/// The distance fraction in the horizontal direction.
@@ -401,8 +399,6 @@ class Alignment extends AlignmentGeometry {
401399
/// whose horizontal component does not depend on the text direction).
402400
class AlignmentDirectional extends AlignmentGeometry {
403401
/// Creates a directional alignment.
404-
///
405-
/// The [start] and [y] arguments must not be null.
406402
const AlignmentDirectional(this.start, this.y);
407403

408404
/// The distance fraction in the horizontal direction.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import 'borders.dart';
2020
class BeveledRectangleBorder extends OutlinedBorder {
2121
/// Creates a border like a [RoundedRectangleBorder] except that the corners
2222
/// are joined by straight lines instead of arcs.
23-
///
24-
/// The arguments must not be null.
2523
const BeveledRectangleBorder({
2624
super.side,
2725
this.borderRadius = BorderRadius.zero,

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ class BorderSide with Diagnosticable {
7777
/// If one of the sides is zero-width with [BorderStyle.none], then the other
7878
/// side is return as-is. If both of the sides are zero-width with
7979
/// [BorderStyle.none], then [BorderSide.none] is returned.
80-
///
81-
/// The arguments must not be null.
8280
static BorderSide merge(BorderSide a, BorderSide b) {
8381
assert(canMerge(a, b));
8482
final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0;
@@ -243,8 +241,6 @@ class BorderSide with Diagnosticable {
243241
///
244242
/// Two sides can be merged if one or both are zero-width with
245243
/// [BorderStyle.none], or if they both have the same color and style.
246-
///
247-
/// The arguments must not be null.
248244
static bool canMerge(BorderSide a, BorderSide b) {
249245
if ((a.style == BorderStyle.none && a.width == 0.0) ||
250246
(b.style == BorderStyle.none && b.width == 0.0)) {
@@ -256,8 +252,6 @@ class BorderSide with Diagnosticable {
256252

257253
/// Linearly interpolate between two border sides.
258254
///
259-
/// The arguments must not be null.
260-
///
261255
/// {@macro dart.ui.shadow.lerp}
262256
static BorderSide lerp(BorderSide a, BorderSide b, double t) {
263257
if (identical(a, b)) {
@@ -665,8 +659,6 @@ abstract class ShapeBorder {
665659
abstract class OutlinedBorder extends ShapeBorder {
666660
/// Abstract const constructor. This constructor enables subclasses to provide
667661
/// const constructors so that they can be used in const expressions.
668-
///
669-
/// The value of [side] must not be null.
670662
const OutlinedBorder({ this.side = BorderSide.none });
671663

672664
@override
@@ -884,8 +876,6 @@ class _CompoundBorder extends ShapeBorder {
884876
/// borders (where all the borders have the same configuration); to render a
885877
/// uniform border, consider using [Canvas.drawRect] directly.
886878
///
887-
/// The arguments must not be null.
888-
///
889879
/// See also:
890880
///
891881
/// * [paintImage], which paints an image in a rectangle on a canvas.

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ class Border extends BoxBorder {
387387
/// Creates a border.
388388
///
389389
/// All the sides of the border default to [BorderSide.none].
390-
///
391-
/// The arguments must not be null.
392390
const Border({
393391
this.top = BorderSide.none,
394392
this.right = BorderSide.none,
@@ -397,8 +395,6 @@ class Border extends BoxBorder {
397395
});
398396

399397
/// Creates a border whose sides are all the same.
400-
///
401-
/// The `side` argument must not be null.
402398
const Border.fromBorderSide(BorderSide side)
403399
: top = side,
404400
right = side,
@@ -410,7 +406,7 @@ class Border extends BoxBorder {
410406
/// The `vertical` argument applies to the [left] and [right] sides, and the
411407
/// `horizontal` argument applies to the [top] and [bottom] sides.
412408
///
413-
/// All arguments default to [BorderSide.none] and must not be null.
409+
/// All arguments default to [BorderSide.none].
414410
const Border.symmetric({
415411
BorderSide vertical = BorderSide.none,
416412
BorderSide horizontal = BorderSide.none,
@@ -437,8 +433,6 @@ class Border extends BoxBorder {
437433
///
438434
/// It is only valid to call this if [BorderSide.canMerge] returns true for
439435
/// the pairwise combination of each side on both [Border]s.
440-
///
441-
/// The arguments must not be null.
442436
static Border merge(Border a, Border b) {
443437
assert(BorderSide.canMerge(a.top, b.top));
444438
assert(BorderSide.canMerge(a.right, b.right));
@@ -761,8 +755,6 @@ class BorderDirectional extends BoxBorder {
761755
/// the trailing edge. They are resolved during [paint].
762756
///
763757
/// All the sides of the border default to [BorderSide.none].
764-
///
765-
/// The arguments must not be null.
766758
const BorderDirectional({
767759
this.top = BorderSide.none,
768760
this.start = BorderSide.none,
@@ -775,8 +767,6 @@ class BorderDirectional extends BoxBorder {
775767
///
776768
/// It is only valid to call this if [BorderSide.canMerge] returns true for
777769
/// the pairwise combination of each side on both [BorderDirectional]s.
778-
///
779-
/// The arguments must not be null.
780770
static BorderDirectional merge(BorderDirectional a, BorderDirectional b) {
781771
assert(BorderSide.canMerge(a.top, b.top));
782772
assert(BorderSide.canMerge(a.start, b.start));

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ class BoxDecoration extends Decoration {
8484
/// * If [boxShadow] is null, this decoration does not paint a shadow.
8585
/// * If [gradient] is null, this decoration does not paint gradients.
8686
/// * If [backgroundBlendMode] is null, this decoration paints with [BlendMode.srcOver]
87-
///
88-
/// The [shape] argument must not be null.
8987
const BoxDecoration({
9088
this.color,
9189
this.image,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import 'borders.dart';
3030
/// * [Border], which, when used with [BoxDecoration], can also describe a circle.
3131
class CircleBorder extends OutlinedBorder {
3232
/// Create a circle border.
33-
///
34-
/// The [side] argument must not be null.
3533
const CircleBorder({ super.side, this.eccentricity = 0.0 })
3634
: assert(eccentricity >= 0.0, 'The eccentricity argument $eccentricity is not greater than or equal to zero.'),
3735
assert(eccentricity <= 1.0, 'The eccentricity argument $eccentricity is not less than or equal to one.');

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ Color _colorFromHue(
8686
class HSVColor {
8787
/// Creates a color.
8888
///
89-
/// All the arguments must not be null and be in their respective ranges. See
90-
/// the fields for each parameter for a description of their ranges.
89+
/// All the arguments must be in their respective ranges. See the fields for
90+
/// each parameter for a description of their ranges.
9191
const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value)
9292
: assert(alpha >= 0.0),
9393
assert(alpha <= 1.0),
@@ -254,8 +254,8 @@ class HSVColor {
254254
class HSLColor {
255255
/// Creates a color.
256256
///
257-
/// All the arguments must not be null and be in their respective ranges. See
258-
/// the fields for each parameter for a description of their ranges.
257+
/// All the arguments must be in their respective ranges. See the fields for
258+
/// each parameter for a description of their ranges.
259259
const HSLColor.fromAHSL(this.alpha, this.hue, this.saturation, this.lightness)
260260
: assert(alpha >= 0.0),
261261
assert(alpha <= 1.0),
@@ -499,8 +499,6 @@ class ColorSwatch<T> extends Color {
499499
/// [DiagnosticsProperty] that has an [Color] as value.
500500
class ColorProperty extends DiagnosticsProperty<Color> {
501501
/// Create a diagnostics property for [Color].
502-
///
503-
/// The [showName], [style], and [level] arguments must not be null.
504502
ColorProperty(
505503
String super.name,
506504
super.value, {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import 'edge_insets.dart';
3333
/// radius in a step function instead of gradually like the
3434
/// [ContinuousRectangleBorder].
3535
class ContinuousRectangleBorder extends OutlinedBorder {
36-
/// The arguments must not be null.
36+
/// Creates a [ContinuousRectangleBorder].
3737
const ContinuousRectangleBorder({
3838
super.side,
3939
this.borderRadius = BorderRadius.zero,

0 commit comments

Comments
 (0)