Skip to content

Commit

Permalink
Remove 'must not be null' comments from various libraries. (#134984)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
gspencergoog authored Sep 20, 2023
1 parent a1f8c99 commit 8cda3be
Show file tree
Hide file tree
Showing 70 changed files with 176 additions and 461 deletions.
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/animation/animation_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ class AnimationController extends Animation<double>
/// value at which this animation is deemed to be completed. It cannot be
/// null.
///
/// * `vsync` is the [TickerProvider] for the current context. It can be
/// changed by calling [resync]. It is required and must not be null. See
/// [TickerProvider] for advice on obtaining a ticker provider.
/// * `vsync` is the required [TickerProvider] for the current context. It can
/// be changed by calling [resync]. See [TickerProvider] for advice on
/// obtaining a ticker provider.
AnimationController({
double? value,
this.duration,
Expand All @@ -258,9 +258,9 @@ class AnimationController extends Animation<double>
/// * [debugLabel] is a string to help identify this animation during
/// debugging (used by [toString]).
///
/// * `vsync` is the [TickerProvider] for the current context. It can be
/// changed by calling [resync]. It is required and must not be null. See
/// [TickerProvider] for advice on obtaining a ticker provider.
/// * `vsync` is the required [TickerProvider] for the current context. It can
/// be changed by calling [resync]. See [TickerProvider] for advice on
/// obtaining a ticker provider.
///
/// This constructor is most useful for animations that will be driven using a
/// physics simulation, especially when the physics simulation has no
Expand Down
17 changes: 7 additions & 10 deletions packages/flutter/lib/src/animation/animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ class ReverseAnimation extends Animation<double>
with AnimationLazyListenerMixin, AnimationLocalStatusListenersMixin {

/// Creates a reverse animation.
///
/// The parent argument must not be null.
ReverseAnimation(this.parent);

/// The animation whose value and direction this animation is reversing.
Expand Down Expand Up @@ -376,8 +374,6 @@ class ReverseAnimation extends Animation<double>
/// [Curve].
class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<double> {
/// Creates a curved animation.
///
/// The parent and curve arguments must not be null.
CurvedAnimation({
required this.parent,
required this.curve,
Expand Down Expand Up @@ -631,8 +627,9 @@ class TrainHoppingAnimation extends Animation<double>
/// animation otherwise.
abstract class CompoundAnimation<T> extends Animation<T>
with AnimationLazyListenerMixin, AnimationLocalListenersMixin, AnimationLocalStatusListenersMixin {
/// Creates a CompoundAnimation. Both arguments must be non-null. Either can
/// be a CompoundAnimation itself to combine multiple animations.
/// Creates a [CompoundAnimation].
///
/// Either argument can be a [CompoundAnimation] itself to combine multiple animations.
CompoundAnimation({
required this.first,
required this.next,
Expand Down Expand Up @@ -720,8 +717,8 @@ class AnimationMean extends CompoundAnimation<double> {
class AnimationMax<T extends num> extends CompoundAnimation<T> {
/// Creates an [AnimationMax].
///
/// Both arguments must be non-null. Either can be an [AnimationMax] itself
/// to combine multiple animations.
/// Either argument can be an [AnimationMax] itself to combine multiple
/// animations.
AnimationMax(Animation<T> first, Animation<T> next) : super(first: first, next: next);

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

@override
Expand Down
17 changes: 1 addition & 16 deletions packages/flutter/lib/src/animation/curves.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ class _Linear extends Curve {
/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_sawtooth.mp4}
class SawTooth extends Curve {
/// Creates a sawtooth curve.
///
/// The [count] argument must not be null.
const SawTooth(this.count);

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

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

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

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

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

/// The curve that is being flipped.
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/animation/tween.dart
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ class ConstantTween<T> extends Tween<T> {
/// [AnimationController].
class CurveTween extends Animatable<double> {
/// Creates a curve tween.
///
/// The [curve] argument must not be null.
CurveTween({ required this.curve });

/// The curve to use when transforming the value of the animation.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/animation/tween_sequence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FlippedTweenSequence extends TweenSequence<double> {
class TweenSequenceItem<T> {
/// Construct a TweenSequenceItem.
///
/// The [tween] must not be null and [weight] must be greater than 0.0.
/// The [weight] must be greater than 0.0.
const TweenSequenceItem({
required this.tween,
required this.weight,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/cupertino/activity_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class CupertinoActivityIndicator extends StatefulWidget {

/// Radius of the spinner widget.
///
/// Defaults to 10px. Must be positive and cannot be null.
/// Defaults to 10 pixels. Must be positive.
final double radius;

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

@override
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/cupertino/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ class CupertinoApp extends StatefulWidget {
/// unsupported route.
///
/// This class creates an instance of [WidgetsApp].
///
/// The boolean arguments, [routes], and [navigatorObservers], must not be null.
const CupertinoApp({
super.key,
this.navigatorKey,
Expand Down
11 changes: 3 additions & 8 deletions packages/flutter/lib/src/cupertino/bottom_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
assert(height >= 0.0);

/// The interactive items laid out within the bottom navigation bar.
///
/// Must not be null.
final List<BottomNavigationBarItem> items;

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

/// The index into [items] of the current active item.
///
/// Must not be null and must inclusively be between 0 and the number of tabs
/// minus 1.
/// Must be between 0 and the number of tabs minus 1, inclusive.
final int currentIndex;

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

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

/// The height of the [CupertinoTabBar].
///
/// Defaults to 50.0. Must not be null.
/// Defaults to 50.
final double height;

/// The border of the [CupertinoTabBar].
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/cupertino/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CupertinoButton extends StatefulWidget {
/// Ignored if the [CupertinoButton] doesn't also have a [color].
///
/// Defaults to [CupertinoColors.quaternarySystemFill] when [color] is
/// specified. Must not be null.
/// specified.
final Color disabledColor;

/// The callback that is called when the button is tapped or otherwise activated.
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/src/cupertino/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class CupertinoCheckbox extends StatefulWidget {
/// can only be null if [tristate] is true.
/// * [onChanged], which is called when the value of the checkbox should
/// change. It can be set to null to disable the checkbox.
///
/// The values of [tristate] and [autofocus] must not be null.
const CupertinoCheckbox({
super.key,
required this.value,
Expand Down
12 changes: 2 additions & 10 deletions packages/flutter/lib/src/cupertino/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,6 @@ abstract final class CupertinoColors {
class CupertinoDynamicColor extends Color with Diagnosticable {
/// Creates an adaptive [Color] that changes its effective color based on the
/// [BuildContext] given. The default effective color is [color].
///
/// All the colors must not be null.
const CupertinoDynamicColor({
String? debugLabel,
required Color color,
Expand Down Expand Up @@ -768,8 +766,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
/// given [BuildContext]'s brightness (from [MediaQueryData.platformBrightness]
/// or [CupertinoThemeData.brightness]) and accessibility contrast setting
/// ([MediaQueryData.highContrast]). The default effective color is [color].
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightnessAndContrast({
String? debugLabel,
required Color color,
Expand All @@ -791,8 +787,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
/// Creates an adaptive [Color] that changes its effective color based on the given
/// [BuildContext]'s brightness (from [MediaQueryData.platformBrightness] or
/// [CupertinoThemeData.brightness]). The default effective color is [color].
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightness({
String? debugLabel,
required Color color,
Expand Down Expand Up @@ -828,8 +822,8 @@ class CupertinoDynamicColor extends Color with Diagnosticable {

/// The current effective color.
///
/// Must not be null. Defaults to [color] if this [CupertinoDynamicColor] has
/// never been resolved.
/// Defaults to [color] if this [CupertinoDynamicColor] has never been
/// resolved.
final Color _effectiveColor;

@override
Expand Down Expand Up @@ -1158,8 +1152,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
}

/// Creates a diagnostics property for [CupertinoDynamicColor].
///
/// The [showName], [style], and [level] arguments must not be null.
DiagnosticsProperty<Color> createCupertinoColorProperty(
String name,
Color? value, {
Expand Down
10 changes: 3 additions & 7 deletions packages/flutter/lib/src/cupertino/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ enum _ContextMenuLocation {
class CupertinoContextMenu extends StatefulWidget {
/// Create a context menu.
///
/// [actions] is required and cannot be null or empty.
///
/// [child] is required and cannot be null.
/// The [actions] parameter cannot be empty.
CupertinoContextMenu({
super.key,
required this.actions,
Expand All @@ -153,9 +151,7 @@ class CupertinoContextMenu extends StatefulWidget {
/// Use instead of the default constructor when it is needed to have a more
/// custom animation.
///
/// [actions] is required and cannot be null or empty.
///
/// [builder] is required.
/// The [actions] parameter cannot be empty.
CupertinoContextMenu.builder({
super.key,
required this.actions,
Expand Down Expand Up @@ -389,7 +385,7 @@ class CupertinoContextMenu extends StatefulWidget {
///
/// These actions are typically [CupertinoContextMenuAction]s.
///
/// This parameter cannot be null or empty.
/// This parameter must not be empty.
final List<Widget> actions;

/// If true, clicking on the [CupertinoContextMenuAction]s will
Expand Down
Loading

0 comments on commit 8cda3be

Please sign in to comment.