Skip to content

Commit a1e49be

Browse files
authored
Remove 'must be non-null' and 'must not be null' comments from material. (#134991)
## 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 material library. 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#134984 - flutter/flutter#134992 - flutter/flutter#134993 - flutter/flutter#134994 ## Tests - Documentation only change.
1 parent f4b5fc1 commit a1e49be

File tree

93 files changed

+127
-376
lines changed

Some content is hidden

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

93 files changed

+127
-376
lines changed

packages/flutter/lib/src/material/animated_icons/animated_icons.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ part of material_animated_icons; // ignore: use_string_in_part_of_directives
2929
class AnimatedIcon extends StatelessWidget {
3030
/// Creates an AnimatedIcon.
3131
///
32-
/// The [progress] and [icon] arguments must not be null.
33-
/// The [size] and [color] default to the value given by the current [IconTheme].
32+
/// The [size] and [color] default to the value given by the current
33+
/// [IconTheme].
3434
const AnimatedIcon({
3535
super.key,
3636
required this.icon,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ class MaterialApp extends StatefulWidget {
202202
/// unsupported route.
203203
///
204204
/// This class creates an instance of [WidgetsApp].
205-
///
206-
/// The boolean arguments, [routes], and [navigatorObservers], must not be null.
207205
const MaterialApp({
208206
super.key,
209207
this.navigatorKey,

packages/flutter/lib/src/material/app_bar.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
14361436
/// * <https://material.io/design/components/app-bars-top.html>
14371437
class SliverAppBar extends StatefulWidget {
14381438
/// Creates a Material Design app bar that can be placed in a [CustomScrollView].
1439-
///
1440-
/// The arguments [forceElevated], [primary], [floating], [pinned], [snap]
1441-
/// and [automaticallyImplyLeading] must not be null.
14421439
const SliverAppBar({
14431440
super.key,
14441441
this.leading,

packages/flutter/lib/src/material/app_bar_theme.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ class AppBarTheme with Diagnosticable {
200200

201201
/// Linearly interpolate between two AppBar themes.
202202
///
203-
/// The argument `t` must not be null.
204-
///
205203
/// {@macro dart.ui.shadow.lerp}
206204
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
207205
if (identical(a, b) && a != null) {

packages/flutter/lib/src/material/banner.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ enum MaterialBannerClosedReason {
9393
class MaterialBanner extends StatefulWidget {
9494
/// Creates a [MaterialBanner].
9595
///
96-
/// The [actions], [content], and [forceActionsBelow] must be non-null.
97-
/// The [actions].length must be greater than 0. The [elevation] must be null or
98-
/// non-negative.
96+
/// The length of the [actions] list must not be empty. The [elevation] must
97+
/// be null or non-negative.
9998
const MaterialBanner({
10099
super.key,
101100
required this.content,

packages/flutter/lib/src/material/banner_theme.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ class MaterialBannerThemeData with Diagnosticable {
9797

9898
/// Linearly interpolate between two Banner themes.
9999
///
100-
/// The argument `t` must not be null.
101-
///
102100
/// {@macro dart.ui.shadow.lerp}
103101
static MaterialBannerThemeData lerp(MaterialBannerThemeData? a, MaterialBannerThemeData? b, double t) {
104102
return MaterialBannerThemeData(

packages/flutter/lib/src/material/bottom_app_bar_theme.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class BottomAppBarTheme with Diagnosticable {
9494

9595
/// Linearly interpolate between two BAB themes.
9696
///
97-
/// The argument `t` must not be null.
98-
///
9997
/// {@macro dart.ui.shadow.lerp}
10098
static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) {
10199
if (identical(a, b) && a != null) {

packages/flutter/lib/src/material/bottom_navigation_bar.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ enum BottomNavigationBarLandscapeLayout {
8080
/// [BottomNavigationBarType.fixed] when there are less than four items, and
8181
/// [BottomNavigationBarType.shifting] otherwise.
8282
///
83-
/// The length of [items] must be at least two and each item's icon and title/label
84-
/// must not be null.
83+
/// The length of [items] must be at least two and each item's icon and
84+
/// label must not be null.
8585
///
8686
/// * [BottomNavigationBarType.fixed], the default when there are less than
8787
/// four [items]. The selected item is rendered with the
@@ -188,7 +188,7 @@ class BottomNavigationBar extends StatefulWidget {
188188
/// are two or three [items], [BottomNavigationBarType.shifting] otherwise.
189189
///
190190
/// The [iconSize], [selectedFontSize], [unselectedFontSize], and [elevation]
191-
/// arguments must be non-null and non-negative.
191+
/// arguments must be non-negative.
192192
///
193193
/// If [selectedLabelStyle].color and [unselectedLabelStyle].color values
194194
/// are non-null, they will be used instead of [selectedItemColor] and

packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ class BottomNavigationBarThemeData with Diagnosticable {
170170

171171
/// Linearly interpolate between two [BottomNavigationBarThemeData].
172172
///
173-
/// The argument `t` must not be null.
174-
///
175173
/// {@macro dart.ui.shadow.lerp}
176174
static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData? a, BottomNavigationBarThemeData? b, double t) {
177175
if (identical(a, b) && a != null) {
@@ -276,8 +274,6 @@ class BottomNavigationBarThemeData with Diagnosticable {
276274
class BottomNavigationBarTheme extends InheritedWidget {
277275
/// Constructs a bottom navigation bar theme that configures all descendant
278276
/// [BottomNavigationBar] widgets.
279-
///
280-
/// The [data] must not be null.
281277
const BottomNavigationBarTheme({
282278
super.key,
283279
required this.data,

packages/flutter/lib/src/material/bottom_sheet.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,6 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
11331133
/// curve specified with the [curve] argument, after the finger is released. In
11341134
/// such a case, the value of [startingPoint] would be the progress of the
11351135
/// animation at the time when the finger was released.
1136-
///
1137-
/// The [startingPoint] and [curve] arguments must not be null.
11381136
class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
11391137
/// Creates a suspended curve.
11401138
const _BottomSheetSuspendedCurve(

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ import 'theme_data.dart';
4040
class RawMaterialButton extends StatefulWidget {
4141
/// Create a button based on [Semantics], [Material], and [InkWell] widgets.
4242
///
43-
/// The [shape], [elevation], [focusElevation], [hoverElevation],
44-
/// [highlightElevation], [disabledElevation], [padding], [constraints],
45-
/// [autofocus], and [clipBehavior] arguments must not be null. Additionally,
46-
/// [elevation], [focusElevation], [hoverElevation], [highlightElevation], and
47-
/// [disabledElevation] must be non-negative.
43+
/// The [elevation], [focusElevation], [hoverElevation], [highlightElevation],
44+
/// and [disabledElevation] parameters must be non-negative.
4845
const RawMaterialButton({
4946
super.key,
5047
required this.onPressed,
@@ -288,7 +285,7 @@ class RawMaterialButton extends StatefulWidget {
288285

289286
/// {@macro flutter.material.Material.clipBehavior}
290287
///
291-
/// Defaults to [Clip.none], and must not be null.
288+
/// Defaults to [Clip.none].
292289
final Clip clipBehavior;
293290

294291
/// Whether detected gestures should provide acoustic and/or haptic feedback.

packages/flutter/lib/src/material/button_bar_theme.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ class ButtonBarThemeData with Diagnosticable {
233233
class ButtonBarTheme extends InheritedWidget {
234234
/// Constructs a button bar theme that configures all descendent [ButtonBar]
235235
/// widgets.
236-
///
237-
/// The [data] must not be null.
238236
const ButtonBarTheme({
239237
super.key,
240238
required this.data,

packages/flutter/lib/src/material/button_style_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ abstract class ButtonStyleButton extends StatefulWidget {
8989

9090
/// {@macro flutter.material.Material.clipBehavior}
9191
///
92-
/// Defaults to [Clip.none], and must not be null.
92+
/// Defaults to [Clip.none].
9393
final Clip clipBehavior;
9494

9595
/// {@macro flutter.widgets.Focus.focusNode}

packages/flutter/lib/src/material/button_theme.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ enum ButtonBarLayoutBehavior {
6666
/// depend on any inherited themes.
6767
class ButtonTheme extends InheritedTheme {
6868
/// Creates a button theme.
69-
///
70-
/// The [textTheme], [minWidth], [height], and [colorScheme] arguments
71-
/// must not be null.
7269
ButtonTheme({
7370
super.key,
7471
ButtonTextTheme textTheme = ButtonTextTheme.normal,
@@ -108,8 +105,6 @@ class ButtonTheme extends InheritedTheme {
108105
);
109106

110107
/// Creates a button theme from [data].
111-
///
112-
/// The [data] argument must not be null.
113108
const ButtonTheme.fromButtonThemeData({
114109
super.key,
115110
required this.data,
@@ -168,9 +163,7 @@ class ButtonThemeData with Diagnosticable {
168163
/// Create a button theme object that can be used with [ButtonTheme]
169164
/// or [ThemeData].
170165
///
171-
/// The [textTheme], [minWidth], [height], [alignedDropdown], and
172-
/// [layoutBehavior] parameters must not be null. The [minWidth] and
173-
/// [height] parameters must greater than or equal to zero.
166+
/// The [minWidth] and [height] parameters must greater than or equal to zero.
174167
///
175168
/// The ButtonTheme's methods that have a [MaterialButton] parameter and
176169
/// have a name with a `get` prefix are used to configure a

packages/flutter/lib/src/material/calendar_date_picker.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,7 @@ const _DayPickerGridDelegate _dayPickerGridDelegate = _DayPickerGridDelegate();
11431143
class YearPicker extends StatefulWidget {
11441144
/// Creates a year picker.
11451145
///
1146-
/// The [firstDate], [lastDate], [selectedDate], and [onChanged]
1147-
/// arguments must be non-null. The [lastDate] must be after the [firstDate].
1146+
/// The [lastDate] must be after the [firstDate].
11481147
YearPicker({
11491148
super.key,
11501149
DateTime? currentDate,

packages/flutter/lib/src/material/card.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ import 'theme.dart';
5858
class Card extends StatelessWidget {
5959
/// Creates a Material Design card.
6060
///
61-
/// The [elevation] must be null or non-negative. The [borderOnForeground]
62-
/// must not be null.
61+
/// The [elevation] must be null or non-negative.
6362
const Card({
6463
super.key,
6564
this.color,

packages/flutter/lib/src/material/card_theme.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ class CardTheme with Diagnosticable {
110110

111111
/// Linearly interpolate between two Card themes.
112112
///
113-
/// The argument `t` must not be null.
114-
///
115113
/// {@macro dart.ui.shadow.lerp}
116114
static CardTheme lerp(CardTheme? a, CardTheme? b, double t) {
117115
if (identical(a, b) && a != null) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class Checkbox extends StatefulWidget {
7474
/// can only be null if [tristate] is true.
7575
/// * [onChanged], which is called when the value of the checkbox should
7676
/// change. It can be set to null to disable the checkbox.
77-
///
78-
/// The values of [tristate] and [autofocus] must not be null.
7977
const Checkbox({
8078
super.key,
8179
required this.value,
@@ -391,7 +389,7 @@ class Checkbox extends StatefulWidget {
391389
/// this is true. This is only used when [ThemeData.useMaterial3] is set to true.
392390
/// {@endtemplate}
393391
///
394-
/// Must not be null. Defaults to false.
392+
/// Defaults to false.
395393
final bool isError;
396394

397395
/// {@template flutter.material.checkbox.semanticLabel}

packages/flutter/lib/src/material/checkbox_list_tile.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ class CheckboxListTile extends StatelessWidget {
159159
/// can only be null if [tristate] is true.
160160
/// * [onChanged], which is called when the value of the checkbox should
161161
/// change. It can be set to null to disable the checkbox.
162-
///
163-
/// The value of [tristate] must not be null.
164162
const CheckboxListTile({
165163
super.key,
166164
required this.value,

packages/flutter/lib/src/material/chip.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ abstract interface class ChipAttributes {
137137

138138
/// {@macro flutter.material.Material.clipBehavior}
139139
///
140-
/// Defaults to [Clip.none], and must not be null.
140+
/// Defaults to [Clip.none].
141141
Clip get clipBehavior;
142142

143143
/// {@macro flutter.widgets.Focus.focusNode}
@@ -333,7 +333,7 @@ abstract interface class SelectableChipAttributes {
333333
/// If [onSelected] is not null, this value will be used to determine if the
334334
/// select check mark will be shown or not.
335335
///
336-
/// Must not be null. Defaults to false.
336+
/// Defaults to false.
337337
bool get selected;
338338

339339
/// Called when the chip should change between selected and de-selected
@@ -447,7 +447,7 @@ abstract interface class DisabledChipAttributes {
447447
/// For classes which don't have this as a constructor argument, [isEnabled]
448448
/// returns true if their user action callback is set.
449449
///
450-
/// Defaults to true. Cannot be null.
450+
/// Defaults to true.
451451
bool get isEnabled;
452452

453453
/// The color used for the chip's background to indicate that it is not
@@ -561,7 +561,6 @@ abstract interface class TappableChipAttributes {
561561
class Chip extends StatelessWidget implements ChipAttributes, DeletableChipAttributes {
562562
/// Creates a Material Design chip.
563563
///
564-
/// The [label], [autofocus], and [clipBehavior] arguments must not be null.
565564
/// The [elevation] must be null or non-negative.
566565
const Chip({
567566
super.key,
@@ -707,10 +706,8 @@ class RawChip extends StatefulWidget
707706
/// The [onPressed] and [onSelected] callbacks must not both be specified at
708707
/// the same time.
709708
///
710-
/// The [label], [isEnabled], [selected], [autofocus], and [clipBehavior]
711-
/// arguments must not be null. The [pressElevation] and [elevation] must be
712-
/// null or non-negative. Typically, [pressElevation] is greater than
713-
/// [elevation].
709+
/// The [pressElevation] and [elevation] must be null or non-negative.
710+
/// Typically, [pressElevation] is greater than [elevation].
714711
const RawChip({
715712
super.key,
716713
this.defaultProperties,

packages/flutter/lib/src/material/chip_theme.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import 'theme.dart';
4242
/// application.
4343
class ChipTheme extends InheritedTheme {
4444
/// Applies the given theme [data] to [child].
45-
///
46-
/// The [data] and [child] arguments must not be null.
4745
const ChipTheme({
4846
super.key,
4947
required this.data,
@@ -490,8 +488,6 @@ class ChipThemeData with Diagnosticable {
490488

491489
/// Linearly interpolate between two chip themes.
492490
///
493-
/// The arguments must not be null.
494-
///
495491
/// {@macro dart.ui.shadow.lerp}
496492
static ChipThemeData? lerp(ChipThemeData? a, ChipThemeData? b, double t) {
497493
if (identical(a, b)) {

packages/flutter/lib/src/material/choice_chip.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ enum _ChipVariant { flat, elevated }
2222
/// [ChoiceChip]s represent a single choice from a set. Choice chips contain
2323
/// related descriptive text or categories.
2424
///
25-
/// Requires one of its ancestors to be a [Material] widget. The [selected] and
26-
/// [label] arguments must not be null.
25+
/// Requires one of its ancestors to be a [Material] widget.
2726
///
2827
/// {@tool dartpad}
2928
/// This example shows how to create [ChoiceChip]s with [onSelected]. When the

packages/flutter/lib/src/material/data_table.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ typedef DataColumnSortCallback = void Function(int columnIndex, bool ascending);
3636
@immutable
3737
class DataColumn {
3838
/// Creates the configuration for a column of a [DataTable].
39-
///
40-
/// The [label] argument must not be null.
4139
const DataColumn({
4240
required this.label,
4341
this.tooltip,
@@ -112,8 +110,6 @@ class DataColumn {
112110
@immutable
113111
class DataRow {
114112
/// Creates the configuration for a row of a [DataTable].
115-
///
116-
/// The [cells] argument must not be null.
117113
const DataRow({
118114
this.key,
119115
this.selected = false,
@@ -126,8 +122,6 @@ class DataRow {
126122

127123
/// Creates the configuration for a row of a [DataTable], deriving
128124
/// the key from a row index.
129-
///
130-
/// The [cells] argument must not be null.
131125
DataRow.byIndex({
132126
int? index,
133127
this.selected = false,
@@ -248,8 +242,7 @@ class DataCell {
248242
/// Creates an object to hold the data for a cell in a [DataTable].
249243
///
250244
/// The first argument is the widget to show for the cell, typically
251-
/// a [Text] or [DropdownButton] widget; this becomes the [child]
252-
/// property and must not be null.
245+
/// a [Text] or [DropdownButton] widget.
253246
///
254247
/// If the cell has no data, then a [Text] widget with placeholder
255248
/// text should be provided instead, and then the [placeholder]
@@ -402,7 +395,7 @@ class DataTable extends StatelessWidget {
402395
/// The [columns] argument must be a list of as many [DataColumn]
403396
/// objects as the table is to have columns, ignoring the leading
404397
/// checkbox column if any. The [columns] argument must have a
405-
/// length greater than zero and must not be null.
398+
/// length greater than zero.
406399
///
407400
/// The [rows] argument must be a list of as many [DataRow] objects
408401
/// as the table is to have rows, ignoring the leading heading row
@@ -676,7 +669,7 @@ class DataTable extends StatelessWidget {
676669
/// The data to show in each row (excluding the row that contains
677670
/// the column headings).
678671
///
679-
/// Must be non-null, but may be empty.
672+
/// The list may be empty.
680673
final List<DataRow> rows;
681674

682675
/// {@template flutter.material.dataTable.dividerThickness}
@@ -712,7 +705,7 @@ class DataTable extends StatelessWidget {
712705
///
713706
/// This can be used to clip the content within the border of the [DataTable].
714707
///
715-
/// Defaults to [Clip.none], and must not be null.
708+
/// Defaults to [Clip.none].
716709
final Clip clipBehavior;
717710

718711
// Set by the constructor to the index of the only Column that is

0 commit comments

Comments
 (0)