Skip to content

Commit

Permalink
Remove 'must not be null' comments from painting and rendering librar…
Browse files Browse the repository at this point in the history
…ies. (#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
- #134984
- #134991
- #134992
- #134994

## Tests
 - Documentation only change.
  • Loading branch information
gspencergoog committed Sep 20, 2023
1 parent 14b832a commit fe9a2c5
Show file tree
Hide file tree
Showing 59 changed files with 79 additions and 309 deletions.
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/_network_image_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer bu
@immutable
class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkImage> implements image_provider.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 });

@override
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/_network_image_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class NetworkImage
extends image_provider.ImageProvider<image_provider.NetworkImage>
implements image_provider.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});

@override
Expand Down
4 changes: 0 additions & 4 deletions packages/flutter/lib/src/painting/alignment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ abstract class AlignmentGeometry {
/// whether the horizontal direction depends on the [TextDirection].
class Alignment extends AlignmentGeometry {
/// Creates an alignment.
///
/// The [x] and [y] arguments must not be null.
const Alignment(this.x, this.y);

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

/// The distance fraction in the horizontal direction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import 'borders.dart';
class BeveledRectangleBorder extends OutlinedBorder {
/// Creates a border like a [RoundedRectangleBorder] except that the corners
/// are joined by straight lines instead of arcs.
///
/// The arguments must not be null.
const BeveledRectangleBorder({
super.side,
this.borderRadius = BorderRadius.zero,
Expand Down
10 changes: 0 additions & 10 deletions packages/flutter/lib/src/painting/borders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class BorderSide with Diagnosticable {
/// If one of the sides is zero-width with [BorderStyle.none], then the other
/// side is return as-is. If both of the sides are zero-width with
/// [BorderStyle.none], then [BorderSide.none] is returned.
///
/// The arguments must not be null.
static BorderSide merge(BorderSide a, BorderSide b) {
assert(canMerge(a, b));
final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0;
Expand Down Expand Up @@ -243,8 +241,6 @@ class BorderSide with Diagnosticable {
///
/// Two sides can be merged if one or both are zero-width with
/// [BorderStyle.none], or if they both have the same color and style.
///
/// The arguments must not be null.
static bool canMerge(BorderSide a, BorderSide b) {
if ((a.style == BorderStyle.none && a.width == 0.0) ||
(b.style == BorderStyle.none && b.width == 0.0)) {
Expand All @@ -256,8 +252,6 @@ class BorderSide with Diagnosticable {

/// Linearly interpolate between two border sides.
///
/// The arguments must not be null.
///
/// {@macro dart.ui.shadow.lerp}
static BorderSide lerp(BorderSide a, BorderSide b, double t) {
if (identical(a, b)) {
Expand Down Expand Up @@ -665,8 +659,6 @@ abstract class ShapeBorder {
abstract class OutlinedBorder extends ShapeBorder {
/// Abstract const constructor. This constructor enables subclasses to provide
/// 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 });

@override
Expand Down Expand Up @@ -884,8 +876,6 @@ class _CompoundBorder extends ShapeBorder {
/// borders (where all the borders have the same configuration); to render a
/// uniform border, consider using [Canvas.drawRect] directly.
///
/// The arguments must not be null.
///
/// See also:
///
/// * [paintImage], which paints an image in a rectangle on a canvas.
Expand Down
12 changes: 1 addition & 11 deletions packages/flutter/lib/src/painting/box_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ class Border extends BoxBorder {
/// Creates a border.
///
/// All the sides of the border default to [BorderSide.none].
///
/// The arguments must not be null.
const Border({
this.top = BorderSide.none,
this.right = BorderSide.none,
Expand All @@ -397,8 +395,6 @@ class Border extends BoxBorder {
});

/// Creates a border whose sides are all the same.
///
/// The `side` argument must not be null.
const Border.fromBorderSide(BorderSide side)
: top = side,
right = side,
Expand All @@ -410,7 +406,7 @@ class Border extends BoxBorder {
/// The `vertical` argument applies to the [left] and [right] sides, and the
/// `horizontal` argument applies to the [top] and [bottom] sides.
///
/// All arguments default to [BorderSide.none] and must not be null.
/// All arguments default to [BorderSide.none].
const Border.symmetric({
BorderSide vertical = BorderSide.none,
BorderSide horizontal = BorderSide.none,
Expand All @@ -437,8 +433,6 @@ class Border extends BoxBorder {
///
/// It is only valid to call this if [BorderSide.canMerge] returns true for
/// the pairwise combination of each side on both [Border]s.
///
/// The arguments must not be null.
static Border merge(Border a, Border b) {
assert(BorderSide.canMerge(a.top, b.top));
assert(BorderSide.canMerge(a.right, b.right));
Expand Down Expand Up @@ -761,8 +755,6 @@ class BorderDirectional extends BoxBorder {
/// the trailing edge. They are resolved during [paint].
///
/// All the sides of the border default to [BorderSide.none].
///
/// The arguments must not be null.
const BorderDirectional({
this.top = BorderSide.none,
this.start = BorderSide.none,
Expand All @@ -775,8 +767,6 @@ class BorderDirectional extends BoxBorder {
///
/// It is only valid to call this if [BorderSide.canMerge] returns true for
/// the pairwise combination of each side on both [BorderDirectional]s.
///
/// The arguments must not be null.
static BorderDirectional merge(BorderDirectional a, BorderDirectional b) {
assert(BorderSide.canMerge(a.top, b.top));
assert(BorderSide.canMerge(a.start, b.start));
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/box_decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class BoxDecoration extends Decoration {
/// * If [boxShadow] is null, this decoration does not paint a shadow.
/// * If [gradient] is null, this decoration does not paint gradients.
/// * If [backgroundBlendMode] is null, this decoration paints with [BlendMode.srcOver]
///
/// The [shape] argument must not be null.
const BoxDecoration({
this.color,
this.image,
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/circle_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import 'borders.dart';
/// * [Border], which, when used with [BoxDecoration], can also describe a circle.
class CircleBorder extends OutlinedBorder {
/// Create a circle border.
///
/// The [side] argument must not be null.
const CircleBorder({ super.side, this.eccentricity = 0.0 })
: assert(eccentricity >= 0.0, 'The eccentricity argument $eccentricity is not greater than or equal to zero.'),
assert(eccentricity <= 1.0, 'The eccentricity argument $eccentricity is not less than or equal to one.');
Expand Down
10 changes: 4 additions & 6 deletions packages/flutter/lib/src/painting/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ Color _colorFromHue(
class HSVColor {
/// Creates a color.
///
/// All the arguments must not be null and be in their respective ranges. See
/// the fields for each parameter for a description of their ranges.
/// All the arguments must be in their respective ranges. See the fields for
/// each parameter for a description of their ranges.
const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value)
: assert(alpha >= 0.0),
assert(alpha <= 1.0),
Expand Down Expand Up @@ -254,8 +254,8 @@ class HSVColor {
class HSLColor {
/// Creates a color.
///
/// All the arguments must not be null and be in their respective ranges. See
/// the fields for each parameter for a description of their ranges.
/// All the arguments must be in their respective ranges. See the fields for
/// each parameter for a description of their ranges.
const HSLColor.fromAHSL(this.alpha, this.hue, this.saturation, this.lightness)
: assert(alpha >= 0.0),
assert(alpha <= 1.0),
Expand Down Expand Up @@ -499,8 +499,6 @@ class ColorSwatch<T> extends Color {
/// [DiagnosticsProperty] that has an [Color] as value.
class ColorProperty extends DiagnosticsProperty<Color> {
/// Create a diagnostics property for [Color].
///
/// The [showName], [style], and [level] arguments must not be null.
ColorProperty(
String super.name,
super.value, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import 'edge_insets.dart';
/// radius in a step function instead of gradually like the
/// [ContinuousRectangleBorder].
class ContinuousRectangleBorder extends OutlinedBorder {
/// The arguments must not be null.
/// Creates a [ContinuousRectangleBorder].
const ContinuousRectangleBorder({
super.side,
this.borderRadius = BorderRadius.zero,
Expand Down
12 changes: 3 additions & 9 deletions packages/flutter/lib/src/painting/decoration_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ enum ImageRepeat {
@immutable
class DecorationImage {
/// Creates an image to show in a [BoxDecoration].
///
/// The [image], [alignment], [repeat], and [matchTextDirection] arguments
/// must not be null.
const DecorationImage({
required this.image,
this.onError,
Expand Down Expand Up @@ -173,9 +170,9 @@ class DecorationImage {

/// Creates a [DecorationImagePainter] for this [DecorationImage].
///
/// The `onChanged` argument must not be null. It will be called whenever the
/// image needs to be repainted, e.g. because it is loading incrementally or
/// because it is animated.
/// The `onChanged` argument will be called whenever the image needs to be
/// repainted, e.g. because it is loading incrementally or because it is
/// animated.
DecorationImagePainter createPainter(VoidCallback onChanged) {
return _DecorationImagePainter._(this, onChanged);
}
Expand Down Expand Up @@ -502,9 +499,6 @@ void debugFlushLastFrameImageSizeInfo() {
/// bilinear interpolation, rather than the default [FilterQuality.none] which corresponds
/// to nearest-neighbor.
///
/// The `canvas`, `rect`, `image`, `scale`, `alignment`, `repeat`, `flipHorizontally` and `filterQuality`
/// arguments must not be null.
///
/// See also:
///
/// * [paintBorder], which paints a border around a rectangle on a canvas.
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/flutter_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class FlutterLogoDecoration extends Decoration {
///
/// The [style] controls whether and where to draw the "Flutter" label. If one
/// is shown, the [textColor] controls the color of the label.
///
/// The [textColor], [style], and [margin] arguments must not be null.
const FlutterLogoDecoration({
this.textColor = const Color(0xFF757575),
this.style = FlutterLogoStyle.markOnly,
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/fractional_offset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import 'basic_types.dart';
@immutable
class FractionalOffset extends Alignment {
/// Creates a fractional offset.
///
/// The [dx] and [dy] arguments must not be null.
const FractionalOffset(double dx, double dy)
: super(dx * 2.0 - 1.0, dy * 2.0 - 1.0);

Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/painting/geometry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import 'basic_types.dart';
/// container.
///
/// Used by [Tooltip] to position a tooltip relative to its parent.
///
/// The arguments must not be null.
Offset positionDependentBox({
required Size size,
required Size childSize,
Expand Down
13 changes: 5 additions & 8 deletions packages/flutter/lib/src/painting/gradient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class GradientRotation extends GradientTransform {
abstract class Gradient {
/// Initialize the gradient's colors and stops.
///
/// The [colors] argument must not be null, and must have at least two colors
/// (the length is not verified until the [createShader] method is called).
/// The [colors] argument must have at least two colors (the length is not
/// verified until the [createShader] method is called).
///
/// If specified, the [stops] argument must have the same number of entries as
/// [colors] (this is also not verified until the [createShader] method is
Expand Down Expand Up @@ -374,8 +374,7 @@ abstract class Gradient {
class LinearGradient extends Gradient {
/// Creates a linear gradient.
///
/// The [colors] argument must not be null. If [stops] is non-null, it must
/// have the same length as [colors].
/// If [stops] is non-null, it must have the same length as [colors].
const LinearGradient({
this.begin = Alignment.centerLeft,
this.end = Alignment.centerRight,
Expand Down Expand Up @@ -625,8 +624,7 @@ class LinearGradient extends Gradient {
class RadialGradient extends Gradient {
/// Creates a radial gradient.
///
/// The [colors] argument must not be null. If [stops] is non-null, it must
/// have the same length as [colors].
/// If [stops] is non-null, it must have the same length as [colors].
const RadialGradient({
this.center = Alignment.center,
this.radius = 0.5,
Expand Down Expand Up @@ -921,8 +919,7 @@ class RadialGradient extends Gradient {
class SweepGradient extends Gradient {
/// Creates a sweep gradient.
///
/// The [colors] argument must not be null. If [stops] is non-null, it must
/// have the same length as [colors].
/// If [stops] is non-null, it must have the same length as [colors].
const SweepGradient({
this.center = Alignment.center,
this.startAngle = 0.0,
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter/lib/src/painting/image_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ class ImageCache {
/// completely discarded by the cache. It should be set to false when calls
/// to evict are trying to relieve memory pressure, since an image with a
/// listener will not actually be evicted from memory, and subsequent attempts
/// to load it will end up allocating more memory for the image again. The
/// argument must not be null.
/// to load it will end up allocating more memory for the image again.
///
/// See also:
///
Expand Down Expand Up @@ -313,8 +312,6 @@ class ImageCache {
/// if not, calls the given callback to obtain it first. In either case, the
/// key is moved to the 'most recently used' position.
///
/// The arguments must not be null. The `loader` cannot return null.
///
/// In the event that the loader throws an exception, it will be caught only if
/// `onError` is also provided. When an exception is caught resolving an image,
/// no completers are cached and `null` is returned instead of a new
Expand Down
18 changes: 4 additions & 14 deletions packages/flutter/lib/src/painting/image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ abstract class ImageProvider<T extends Object> {
/// The location may be [ImageCacheStatus.untracked], indicating that this
/// image provider's key is not available in the [ImageCache].
///
/// The `cache` and `configuration` parameters must not be null. If the
/// `handleError` parameter is null, errors will be reported to
/// If the `handleError` parameter is null, errors will be reported to
/// [FlutterError.onError], and the method will return null.
///
/// A completed return value of null indicates that an error has occurred.
Expand Down Expand Up @@ -655,8 +654,6 @@ class _AbstractImageStreamCompleter extends ImageStreamCompleter {}
@immutable
class AssetBundleImageKey {
/// Creates the key for an [AssetImage] or [AssetBundleImageProvider].
///
/// The arguments must not be null.
const AssetBundleImageKey({
required this.bundle,
required this.name,
Expand Down Expand Up @@ -1402,8 +1399,6 @@ class ResizeImage extends ImageProvider<ResizeImageKey> {
// our cache if the headers describe the image as having expired at that point.
abstract class NetworkImage extends ImageProvider<NetworkImage> {
/// Creates an object that fetches the image at the given URL.
///
/// The arguments [url] and [scale] must not be null.
const factory NetworkImage(String url, { double scale, Map<String, String>? headers }) = network_image.NetworkImage;

/// The URL from which the image will be fetched.
Expand Down Expand Up @@ -1436,8 +1431,6 @@ abstract class NetworkImage extends ImageProvider<NetworkImage> {
@immutable
class FileImage extends ImageProvider<FileImage> {
/// Creates an object that decodes a [File] as an image.
///
/// The arguments must not be null.
const FileImage(this.file, { this.scale = 1.0 });

/// The file to decode into an image.
Expand Down Expand Up @@ -1528,8 +1521,6 @@ class FileImage extends ImageProvider<FileImage> {
@immutable
class MemoryImage extends ImageProvider<MemoryImage> {
/// Creates an object that decodes a [Uint8List] buffer as an image.
///
/// The arguments must not be null.
const MemoryImage(this.bytes, { this.scale = 1.0 });

/// The bytes to decode into an image.
Expand Down Expand Up @@ -1674,10 +1665,9 @@ class MemoryImage extends ImageProvider<MemoryImage> {
class ExactAssetImage extends AssetBundleImageProvider {
/// Creates an object that fetches the given image from an asset bundle.
///
/// The [assetName] and [scale] arguments must not be null. The [scale] arguments
/// defaults to 1.0. The [bundle] argument may be null, in which case the
/// bundle provided in the [ImageConfiguration] passed to the [resolve] call
/// will be used instead.
/// The [scale] argument defaults to 1. The [bundle] argument may be null, in
/// which case the bundle provided in the [ImageConfiguration] passed to the
/// [resolve] call will be used instead.
///
/// The [package] argument must be non-null when fetching an asset that is
/// included in a package. See the documentation for the [ExactAssetImage] class
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/painting/image_resolution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ const double _kLowDprLimit = 2.0;
class AssetImage extends AssetBundleImageProvider {
/// Creates an object that fetches an image from an asset bundle.
///
/// The [assetName] argument must not be null. It should name the main asset
/// from the set of images to choose from. The [package] argument must be
/// non-null when fetching an asset that is included in package. See the
/// documentation for the [AssetImage] class itself for details.
/// The [assetName] argument should name the main asset from the set of images
/// to choose from. The [package] argument must be non-null when fetching an
/// asset that is included in package. See the documentation for the
/// [AssetImage] class itself for details.
const AssetImage(
this.assetName, {
this.bundle,
Expand Down
Loading

0 comments on commit fe9a2c5

Please sign in to comment.