Skip to content

Commit 8cda3be

Browse files
authored
Remove 'must not be null' comments from various libraries. (#134984)
## 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 animation, cupertino, foundation, gestures, semantics, and services libraries. Each of them only had a few, so I lumped them together. 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/flutter#134991 - flutter/flutter#134992 - flutter/flutter#134993 - flutter/flutter#134994 ## Tests - Documentation only change.
1 parent a1f8c99 commit 8cda3be

Some content is hidden

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

70 files changed

+176
-461
lines changed

packages/flutter/lib/src/animation/animation_controller.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ class AnimationController extends Animation<double>
230230
/// value at which this animation is deemed to be completed. It cannot be
231231
/// null.
232232
///
233-
/// * `vsync` is the [TickerProvider] for the current context. It can be
234-
/// changed by calling [resync]. It is required and must not be null. See
235-
/// [TickerProvider] for advice on obtaining a ticker provider.
233+
/// * `vsync` is the required [TickerProvider] for the current context. It can
234+
/// be changed by calling [resync]. See [TickerProvider] for advice on
235+
/// obtaining a ticker provider.
236236
AnimationController({
237237
double? value,
238238
this.duration,
@@ -258,9 +258,9 @@ class AnimationController extends Animation<double>
258258
/// * [debugLabel] is a string to help identify this animation during
259259
/// debugging (used by [toString]).
260260
///
261-
/// * `vsync` is the [TickerProvider] for the current context. It can be
262-
/// changed by calling [resync]. It is required and must not be null. See
263-
/// [TickerProvider] for advice on obtaining a ticker provider.
261+
/// * `vsync` is the required [TickerProvider] for the current context. It can
262+
/// be changed by calling [resync]. See [TickerProvider] for advice on
263+
/// obtaining a ticker provider.
264264
///
265265
/// This constructor is most useful for animations that will be driven using a
266266
/// physics simulation, especially when the physics simulation has no

packages/flutter/lib/src/animation/animations.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ class ReverseAnimation extends Animation<double>
269269
with AnimationLazyListenerMixin, AnimationLocalStatusListenersMixin {
270270

271271
/// Creates a reverse animation.
272-
///
273-
/// The parent argument must not be null.
274272
ReverseAnimation(this.parent);
275273

276274
/// The animation whose value and direction this animation is reversing.
@@ -376,8 +374,6 @@ class ReverseAnimation extends Animation<double>
376374
/// [Curve].
377375
class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<double> {
378376
/// Creates a curved animation.
379-
///
380-
/// The parent and curve arguments must not be null.
381377
CurvedAnimation({
382378
required this.parent,
383379
required this.curve,
@@ -631,8 +627,9 @@ class TrainHoppingAnimation extends Animation<double>
631627
/// animation otherwise.
632628
abstract class CompoundAnimation<T> extends Animation<T>
633629
with AnimationLazyListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin {
634-
/// Creates a CompoundAnimation. Both arguments must be non-null. Either can
635-
/// be a CompoundAnimation itself to combine multiple animations.
630+
/// Creates a [CompoundAnimation].
631+
///
632+
/// Either argument can be a [CompoundAnimation] itself to combine multiple animations.
636633
CompoundAnimation({
637634
required this.first,
638635
required this.next,
@@ -720,8 +717,8 @@ class AnimationMean extends CompoundAnimation<double> {
720717
class AnimationMax<T extends num> extends CompoundAnimation<T> {
721718
/// Creates an [AnimationMax].
722719
///
723-
/// Both arguments must be non-null. Either can be an [AnimationMax] itself
724-
/// to combine multiple animations.
720+
/// Either argument can be an [AnimationMax] itself to combine multiple
721+
/// animations.
725722
AnimationMax(Animation<T> first, Animation<T> next) : super(first: first, next: next);
726723

727724
@override
@@ -735,8 +732,8 @@ class AnimationMax<T extends num> extends CompoundAnimation<T> {
735732
class AnimationMin<T extends num> extends CompoundAnimation<T> {
736733
/// Creates an [AnimationMin].
737734
///
738-
/// Both arguments must be non-null. Either can be an [AnimationMin] itself
739-
/// to combine multiple animations.
735+
/// Either argument can be an [AnimationMin] itself to combine multiple
736+
/// animations.
740737
AnimationMin(Animation<T> first, Animation<T> next) : super(first: first, next: next);
741738

742739
@override

packages/flutter/lib/src/animation/curves.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ class _Linear extends Curve {
127127
/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_sawtooth.mp4}
128128
class SawTooth extends Curve {
129129
/// Creates a sawtooth curve.
130-
///
131-
/// The [count] argument must not be null.
132130
const SawTooth(this.count);
133131

134132
/// The number of repetitions of the sawtooth pattern in the unit interval.
@@ -157,8 +155,6 @@ class SawTooth extends Curve {
157155
/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_interval.mp4}
158156
class Interval extends Curve {
159157
/// Creates an interval curve.
160-
///
161-
/// The arguments must not be null.
162158
const Interval(this.begin, this.end, { this.curve = Curves.linear });
163159

164160
/// The largest value for which this interval is 0.0.
@@ -202,8 +198,6 @@ class Interval extends Curve {
202198
/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_threshold.mp4}
203199
class Threshold extends Curve {
204200
/// Creates a threshold curve.
205-
///
206-
/// The [threshold] argument must not be null.
207201
const Threshold(this.threshold);
208202

209203
/// The value before which the curve is 0.0 and after which the curve is 1.0.
@@ -302,8 +296,6 @@ class Cubic extends Curve {
302296
///
303297
/// Rather than creating a new instance, consider using one of the common
304298
/// cubic curves in [Curves].
305-
///
306-
/// The [a] (x1), [b] (y1), [c] (x2) and [d] (y2) arguments must not be null.
307299
const Cubic(this.a, this.b, this.c, this.d);
308300

309301
/// The x coordinate of the first control point.
@@ -599,8 +591,6 @@ abstract class Curve2D extends ParametricCurve<Offset> {
599591
/// * [Curve2D], a parametric curve that maps a double parameter to a 2D location.
600592
class Curve2DSample {
601593
/// Creates an object that holds a sample; used with [Curve2D] subclasses.
602-
///
603-
/// All arguments must not be null.
604594
const Curve2DSample(this.t, this.value);
605595

606596
/// The parametric location of this sample point along the curve.
@@ -659,8 +649,7 @@ class CatmullRomSpline extends Curve2D {
659649
/// control point. The default is chosen so that the slope of the line at the
660650
/// ends matches that of the first or last line segment in the control points.
661651
///
662-
/// The `tension` and `controlPoints` arguments must not be null, and the
663-
/// `controlPoints` list must contain at least four control points to
652+
/// The `controlPoints` list must contain at least four control points to
664653
/// interpolate.
665654
///
666655
/// The internal curve data structures are lazily computed the first time
@@ -860,8 +849,6 @@ class CatmullRomCurve extends Curve {
860849
/// [transform] is called. If you would rather pre-compute the curve, use
861850
/// [CatmullRomCurve.precompute] instead.
862851
///
863-
/// All of the arguments must not be null.
864-
///
865852
/// See also:
866853
///
867854
/// * This [paper on using Catmull-Rom splines](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf).
@@ -1144,8 +1131,6 @@ class CatmullRomCurve extends Curve {
11441131
/// * [CurvedAnimation], which can take a separate curve and reverse curve.
11451132
class FlippedCurve extends Curve {
11461133
/// Creates a flipped curve.
1147-
///
1148-
/// The [curve] argument must not be null.
11491134
const FlippedCurve(this.curve);
11501135

11511136
/// The curve that is being flipped.

packages/flutter/lib/src/animation/tween.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,6 @@ class ConstantTween<T> extends Tween<T> {
547547
/// [AnimationController].
548548
class CurveTween extends Animatable<double> {
549549
/// Creates a curve tween.
550-
///
551-
/// The [curve] argument must not be null.
552550
CurveTween({ required this.curve });
553551

554552
/// The curve to use when transforming the value of the animation.

packages/flutter/lib/src/animation/tween_sequence.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class FlippedTweenSequence extends TweenSequence<double> {
122122
class TweenSequenceItem<T> {
123123
/// Construct a TweenSequenceItem.
124124
///
125-
/// The [tween] must not be null and [weight] must be greater than 0.0.
125+
/// The [weight] must be greater than 0.0.
126126
const TweenSequenceItem({
127127
required this.tween,
128128
required this.weight,

packages/flutter/lib/src/cupertino/activity_indicator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ class CupertinoActivityIndicator extends StatefulWidget {
6767

6868
/// Radius of the spinner widget.
6969
///
70-
/// Defaults to 10px. Must be positive and cannot be null.
70+
/// Defaults to 10 pixels. Must be positive.
7171
final double radius;
7272

7373
/// Determines the percentage of spinner ticks that will be shown. Typical usage would
7474
/// display all ticks, however, this allows for more fine-grained control such as
7575
/// during pull-to-refresh when the drag-down action shows one tick at a time as
7676
/// the user continues to drag down.
7777
///
78-
/// Defaults to 1.0. Must be between 0.0 and 1.0 inclusive, and cannot be null.
78+
/// Defaults to one. Must be between zero and one, inclusive.
7979
final double progress;
8080

8181
@override

packages/flutter/lib/src/cupertino/app.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ class CupertinoApp extends StatefulWidget {
145145
/// unsupported route.
146146
///
147147
/// This class creates an instance of [WidgetsApp].
148-
///
149-
/// The boolean arguments, [routes], and [navigatorObservers], must not be null.
150148
const CupertinoApp({
151149
super.key,
152150
this.navigatorKey,

packages/flutter/lib/src/cupertino/bottom_tab_bar.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
7979
assert(height >= 0.0);
8080

8181
/// The interactive items laid out within the bottom navigation bar.
82-
///
83-
/// Must not be null.
8482
final List<BottomNavigationBarItem> items;
8583

8684
/// The callback that is called when a item is tapped.
@@ -92,8 +90,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
9290

9391
/// The index into [items] of the current active item.
9492
///
95-
/// Must not be null and must inclusively be between 0 and the number of tabs
96-
/// minus 1.
93+
/// Must be between 0 and the number of tabs minus 1, inclusive.
9794
final int currentIndex;
9895

9996
/// The background color of the tab bar. If it contains transparency, the
@@ -113,21 +110,19 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
113110
/// in the unselected state.
114111
///
115112
/// Defaults to a [CupertinoDynamicColor] that matches the disabled foreground
116-
/// color of the native `UITabBar` component. Cannot be null.
113+
/// color of the native `UITabBar` component.
117114
final Color inactiveColor;
118115

119116
/// The size of all of the [BottomNavigationBarItem] icons.
120117
///
121118
/// This value is used to configure the [IconTheme] for the navigation bar.
122119
/// When a [BottomNavigationBarItem.icon] widget is not an [Icon] the widget
123120
/// should configure itself to match the icon theme's size and color.
124-
///
125-
/// Must not be null.
126121
final double iconSize;
127122

128123
/// The height of the [CupertinoTabBar].
129124
///
130-
/// Defaults to 50.0. Must not be null.
125+
/// Defaults to 50.
131126
final double height;
132127

133128
/// The border of the [CupertinoTabBar].

packages/flutter/lib/src/cupertino/button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CupertinoButton extends StatefulWidget {
9595
/// Ignored if the [CupertinoButton] doesn't also have a [color].
9696
///
9797
/// Defaults to [CupertinoColors.quaternarySystemFill] when [color] is
98-
/// specified. Must not be null.
98+
/// specified.
9999
final Color disabledColor;
100100

101101
/// The callback that is called when the button is tapped or otherwise activated.

packages/flutter/lib/src/cupertino/checkbox.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class CupertinoCheckbox extends StatefulWidget {
5757
/// can only be null if [tristate] is true.
5858
/// * [onChanged], which is called when the value of the checkbox should
5959
/// change. It can be set to null to disable the checkbox.
60-
///
61-
/// The values of [tristate] and [autofocus] must not be null.
6260
const CupertinoCheckbox({
6361
super.key,
6462
required this.value,

0 commit comments

Comments
 (0)