Skip to content

Commit 0de8bef

Browse files
authored
Remove unnecessary null checks in flutter/cupertino (flutter#119020)
1 parent 720bea0 commit 0de8bef

31 files changed

+80
-319
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class CupertinoActivityIndicator extends StatefulWidget {
3636
this.color,
3737
this.animating = true,
3838
this.radius = _kDefaultIndicatorRadius,
39-
}) : assert(animating != null),
40-
assert(radius != null),
41-
assert(radius > 0.0),
39+
}) : assert(radius > 0.0),
4240
progress = 1.0;
4341

4442
/// Creates a non-animated iOS-style activity indicator that displays
@@ -52,9 +50,7 @@ class CupertinoActivityIndicator extends StatefulWidget {
5250
this.color,
5351
this.radius = _kDefaultIndicatorRadius,
5452
this.progress = 1.0,
55-
}) : assert(radius != null),
56-
assert(radius > 0.0),
57-
assert(progress != null),
53+
}) : assert(radius > 0.0),
5854
assert(progress >= 0.0),
5955
assert(progress <= 1.0),
6056
animating = false;

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,7 @@ class CupertinoApp extends StatefulWidget {
177177
this.restorationScopeId,
178178
this.scrollBehavior,
179179
this.useInheritedMediaQuery = false,
180-
}) : assert(routes != null),
181-
assert(navigatorObservers != null),
182-
assert(title != null),
183-
assert(showPerformanceOverlay != null),
184-
assert(checkerboardRasterCacheImages != null),
185-
assert(checkerboardOffscreenLayers != null),
186-
assert(showSemanticsDebugger != null),
187-
assert(debugShowCheckedModeBanner != null),
188-
routeInformationProvider = null,
180+
}) : routeInformationProvider = null,
189181
routeInformationParser = null,
190182
routerDelegate = null,
191183
backButtonDispatcher = null,
@@ -222,12 +214,6 @@ class CupertinoApp extends StatefulWidget {
222214
this.scrollBehavior,
223215
this.useInheritedMediaQuery = false,
224216
}) : assert(routerDelegate != null || routerConfig != null),
225-
assert(title != null),
226-
assert(showPerformanceOverlay != null),
227-
assert(checkerboardRasterCacheImages != null),
228-
assert(checkerboardOffscreenLayers != null),
229-
assert(showSemanticsDebugger != null),
230-
assert(debugShowCheckedModeBanner != null),
231217
navigatorObservers = null,
232218
navigatorKey = null,
233219
onGenerateRoute = null,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,12 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
7474
width: 0.0, // 0.0 means one physical pixel
7575
),
7676
),
77-
}) : assert(items != null),
78-
assert(
77+
}) : assert(
7978
items.length >= 2,
8079
"Tabs need at least 2 items to conform to Apple's HIG",
8180
),
82-
assert(currentIndex != null),
8381
assert(0 <= currentIndex && currentIndex < items.length),
84-
assert(iconSize != null),
85-
assert(height != null && height >= 0.0),
86-
assert(inactiveColor != null);
82+
assert(height >= 0.0);
8783

8884
/// The interactive items laid out within the bottom navigation bar.
8985
///

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class CupertinoButton extends StatefulWidget {
5050
this.alignment = Alignment.center,
5151
required this.onPressed,
5252
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
53-
assert(disabledColor != null),
54-
assert(alignment != null),
5553
_filled = false;
5654

5755
/// Creates an iOS-style button with a filled background.
@@ -71,8 +69,6 @@ class CupertinoButton extends StatefulWidget {
7169
this.alignment = Alignment.center,
7270
required this.onPressed,
7371
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
74-
assert(disabledColor != null),
75-
assert(alignment != null),
7672
color = null,
7773
_filled = true;
7874

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
780780
this.darkHighContrastElevatedColor,
781781
this._debugResolveContext,
782782
this._debugLabel,
783-
) : assert(color != null),
784-
assert(darkColor != null),
785-
assert(highContrastColor != null),
786-
assert(darkHighContrastColor != null),
787-
assert(elevatedColor != null),
788-
assert(darkElevatedColor != null),
789-
assert(highContrastElevatedColor != null),
790-
assert(darkHighContrastElevatedColor != null),
791-
assert(_effectiveColor != null),
792-
// The super constructor has to be called with a dummy value in order to mark
783+
) : // The super constructor has to be called with a dummy value in order to mark
793784
// this constructor const.
794785
// The field `value` is overridden in the class implementation.
795786
super(0);
@@ -908,7 +899,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
908899
/// * [maybeResolve], which is similar to this function, but will allow a
909900
/// null `resolvable` color.
910901
static Color resolve(Color resolvable, BuildContext context) {
911-
assert(context != null);
912902
return (resolvable is CupertinoDynamicColor)
913903
? resolvable.resolveFrom(context)
914904
: resolvable;
@@ -931,7 +921,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
931921
if (resolvable == null) {
932922
return null;
933923
}
934-
assert(context != null);
935924
return (resolvable is CupertinoDynamicColor)
936925
? resolvable.resolveFrom(context)
937926
: resolvable;

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ class CupertinoContextMenu extends StatefulWidget {
142142
'This feature was deprecated after v3.4.0-34.1.pre.',
143143
)
144144
this.previewBuilder = _defaultPreviewBuilder,
145-
}) : assert(actions != null && actions.isNotEmpty),
146-
assert(child != null),
145+
}) : assert(actions.isNotEmpty),
147146
builder = ((BuildContext context, Animation<double> animation) => child);
148147

149148
/// Creates a context menu with a custom [builder] controlling the widget.
@@ -158,7 +157,7 @@ class CupertinoContextMenu extends StatefulWidget {
158157
super.key,
159158
required this.actions,
160159
required this.builder,
161-
}) : assert(actions != null && actions.isNotEmpty),
160+
}) : assert(actions.isNotEmpty),
162161
child = null,
163162
previewBuilder = null;
164163

@@ -794,8 +793,7 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
794793
super.filter,
795794
required Rect previousChildRect,
796795
super.settings,
797-
}) : assert(actions != null && actions.isNotEmpty),
798-
assert(contextMenuLocation != null),
796+
}) : assert(actions.isNotEmpty),
799797
_actions = actions,
800798
_builder = builder,
801799
_contextMenuLocation = contextMenuLocation,
@@ -1081,8 +1079,7 @@ class _ContextMenuRouteStatic extends StatefulWidget {
10811079
this.onDismiss,
10821080
required this.orientation,
10831081
this.sheetGlobalKey,
1084-
}) : assert(contextMenuLocation != null),
1085-
assert(orientation != null);
1082+
});
10861083

10871084
final List<Widget>? actions;
10881085
final Widget child;
@@ -1409,9 +1406,7 @@ class _ContextMenuSheet extends StatelessWidget {
14091406
required this.actions,
14101407
required _ContextMenuLocation contextMenuLocation,
14111408
required Orientation orientation,
1412-
}) : assert(actions != null && actions.isNotEmpty),
1413-
assert(contextMenuLocation != null),
1414-
assert(orientation != null),
1409+
}) : assert(actions.isNotEmpty),
14151410
_contextMenuLocation = contextMenuLocation,
14161411
_orientation = orientation;
14171412

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class CupertinoContextMenuAction extends StatefulWidget {
2020
this.isDestructiveAction = false,
2121
this.onPressed,
2222
this.trailingIcon,
23-
}) : assert(child != null),
24-
assert(isDefaultAction != null),
25-
assert(isDestructiveAction != null);
23+
});
2624

2725
/// The widget that will be placed inside the action.
2826
final Widget child;

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ class _DatePickerLayoutDelegate extends MultiChildLayoutDelegate {
8181
_DatePickerLayoutDelegate({
8282
required this.columnWidths,
8383
required this.textDirectionFactor,
84-
}) : assert(columnWidths != null),
85-
assert(textDirectionFactor != null);
84+
});
8685

8786
// The list containing widths of all columns.
8887
final List<double> columnWidths;
@@ -277,14 +276,10 @@ class CupertinoDatePicker extends StatefulWidget {
277276
this.dateOrder,
278277
this.backgroundColor,
279278
}) : initialDateTime = initialDateTime ?? DateTime.now(),
280-
assert(mode != null),
281-
assert(onDateTimeChanged != null),
282-
assert(minimumYear != null),
283279
assert(
284280
minuteInterval > 0 && 60 % minuteInterval == 0,
285281
'minute interval is not a positive integer factor of 60',
286282
) {
287-
assert(this.initialDateTime != null);
288283
assert(
289284
mode != CupertinoDatePickerMode.dateAndTime || minimumDate == null || !this.initialDateTime.isBefore(minimumDate!),
290285
'initial date is before minimum date',
@@ -944,7 +939,6 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
944939
}
945940

946941
void _scrollToDate(DateTime newDate, DateTime fromDate, bool minCheck) {
947-
assert(newDate != null);
948942
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
949943
if (fromDate.year != newDate.year || fromDate.month != newDate.month || fromDate.day != newDate.day) {
950944
_animateColumnControllerToItem(dateController, selectedDayFromInitial);
@@ -1349,7 +1343,6 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
13491343
}
13501344

13511345
void _scrollToDate(DateTime newDate) {
1352-
assert(newDate != null);
13531346
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
13541347
if (selectedYear != newDate.year) {
13551348
_animateColumnControllerToItem(yearController, newDate.year);
@@ -1551,15 +1544,12 @@ class CupertinoTimerPicker extends StatefulWidget {
15511544
this.alignment = Alignment.center,
15521545
this.backgroundColor,
15531546
required this.onTimerDurationChanged,
1554-
}) : assert(mode != null),
1555-
assert(onTimerDurationChanged != null),
1556-
assert(initialTimerDuration >= Duration.zero),
1547+
}) : assert(initialTimerDuration >= Duration.zero),
15571548
assert(initialTimerDuration < const Duration(days: 1)),
15581549
assert(minuteInterval > 0 && 60 % minuteInterval == 0),
15591550
assert(secondInterval > 0 && 60 % secondInterval == 0),
15601551
assert(initialTimerDuration.inMinutes % minuteInterval == 0),
1561-
assert(initialTimerDuration.inSeconds % secondInterval == 0),
1562-
assert(alignment != null);
1552+
assert(initialTimerDuration.inSeconds % secondInterval == 0);
15631553

15641554
/// The mode of the timer picker.
15651555
final CupertinoTimerPickerMode mode;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class CupertinoDesktopTextSelectionToolbarButton extends StatefulWidget {
3737
super.key,
3838
required this.onPressed,
3939
required Widget this.child,
40-
}) : assert(child != null),
41-
buttonItem = null;
40+
}) : buttonItem = null;
4241

4342
/// Create an instance of [CupertinoDesktopTextSelectionToolbarButton] whose child is
4443
/// a [Text] widget styled like the default Mac context menu button.
@@ -66,8 +65,7 @@ class CupertinoDesktopTextSelectionToolbarButton extends StatefulWidget {
6665
CupertinoDesktopTextSelectionToolbarButton.buttonItem({
6766
super.key,
6867
required ContextMenuButtonItem this.buttonItem,
69-
}) : assert(buttonItem != null),
70-
onPressed = buttonItem.onPressed,
68+
}) : onPressed = buttonItem.onPressed,
7169
child = null;
7270

7371
/// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class CupertinoAlertDialog extends StatelessWidget {
201201
this.actionScrollController,
202202
this.insetAnimationDuration = const Duration(milliseconds: 100),
203203
this.insetAnimationCurve = Curves.decelerate,
204-
}) : assert(actions != null);
204+
});
205205

206206
/// The (optional) title of the dialog is displayed in a large font at the top
207207
/// of the dialog.
@@ -665,8 +665,7 @@ class CupertinoActionSheetAction extends StatelessWidget {
665665
this.isDefaultAction = false,
666666
this.isDestructiveAction = false,
667667
required this.child,
668-
}) : assert(child != null),
669-
assert(onPressed != null);
668+
});
670669

671670
/// The callback that is called when the button is tapped.
672671
///
@@ -701,7 +700,7 @@ class CupertinoActionSheetAction extends StatelessWidget {
701700
}
702701

703702
return MouseRegion(
704-
cursor: onPressed != null && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
703+
cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
705704
child: GestureDetector(
706705
onTap: onPressed,
707706
behavior: HitTestBehavior.opaque,
@@ -896,7 +895,6 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
896895
}
897896

898897
void _placeChildInSlot(RenderObject child, _AlertDialogSections slot) {
899-
assert(slot != null);
900898
switch (slot) {
901899
case _AlertDialogSections.contentSection:
902900
renderObject.contentSection = child as RenderBox;
@@ -1443,7 +1441,7 @@ class _CupertinoAlertActionSection extends StatelessWidget {
14431441
this.scrollController,
14441442
this.hasCancelButton = false,
14451443
this.isActionSheet = false,
1446-
}) : assert(children != null);
1444+
});
14471445

14481446
final List<Widget> children;
14491447

@@ -1593,9 +1591,7 @@ class CupertinoDialogAction extends StatelessWidget {
15931591
this.isDestructiveAction = false,
15941592
this.textStyle,
15951593
required this.child,
1596-
}) : assert(child != null),
1597-
assert(isDefaultAction != null),
1598-
assert(isDestructiveAction != null);
1594+
});
15991595

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

0 commit comments

Comments
 (0)