Skip to content

Commit

Permalink
Remove unnecessary null checks in flutter/cupertino (#119020)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Jan 24, 2023
1 parent 720bea0 commit 0de8bef
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 319 deletions.
8 changes: 2 additions & 6 deletions packages/flutter/lib/src/cupertino/activity_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class CupertinoActivityIndicator extends StatefulWidget {
this.color,
this.animating = true,
this.radius = _kDefaultIndicatorRadius,
}) : assert(animating != null),
assert(radius != null),
assert(radius > 0.0),
}) : assert(radius > 0.0),
progress = 1.0;

/// Creates a non-animated iOS-style activity indicator that displays
Expand All @@ -52,9 +50,7 @@ class CupertinoActivityIndicator extends StatefulWidget {
this.color,
this.radius = _kDefaultIndicatorRadius,
this.progress = 1.0,
}) : assert(radius != null),
assert(radius > 0.0),
assert(progress != null),
}) : assert(radius > 0.0),
assert(progress >= 0.0),
assert(progress <= 1.0),
animating = false;
Expand Down
16 changes: 1 addition & 15 deletions packages/flutter/lib/src/cupertino/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,7 @@ class CupertinoApp extends StatefulWidget {
this.restorationScopeId,
this.scrollBehavior,
this.useInheritedMediaQuery = false,
}) : assert(routes != null),
assert(navigatorObservers != null),
assert(title != null),
assert(showPerformanceOverlay != null),
assert(checkerboardRasterCacheImages != null),
assert(checkerboardOffscreenLayers != null),
assert(showSemanticsDebugger != null),
assert(debugShowCheckedModeBanner != null),
routeInformationProvider = null,
}) : routeInformationProvider = null,
routeInformationParser = null,
routerDelegate = null,
backButtonDispatcher = null,
Expand Down Expand Up @@ -222,12 +214,6 @@ class CupertinoApp extends StatefulWidget {
this.scrollBehavior,
this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null),
assert(title != null),
assert(showPerformanceOverlay != null),
assert(checkerboardRasterCacheImages != null),
assert(checkerboardOffscreenLayers != null),
assert(showSemanticsDebugger != null),
assert(debugShowCheckedModeBanner != null),
navigatorObservers = null,
navigatorKey = null,
onGenerateRoute = null,
Expand Down
8 changes: 2 additions & 6 deletions packages/flutter/lib/src/cupertino/bottom_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
width: 0.0, // 0.0 means one physical pixel
),
),
}) : assert(items != null),
assert(
}) : assert(
items.length >= 2,
"Tabs need at least 2 items to conform to Apple's HIG",
),
assert(currentIndex != null),
assert(0 <= currentIndex && currentIndex < items.length),
assert(iconSize != null),
assert(height != null && height >= 0.0),
assert(inactiveColor != null);
assert(height >= 0.0);

/// The interactive items laid out within the bottom navigation bar.
///
Expand Down
4 changes: 0 additions & 4 deletions packages/flutter/lib/src/cupertino/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class CupertinoButton extends StatefulWidget {
this.alignment = Alignment.center,
required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(disabledColor != null),
assert(alignment != null),
_filled = false;

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

Expand Down
13 changes: 1 addition & 12 deletions packages/flutter/lib/src/cupertino/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,7 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
this.darkHighContrastElevatedColor,
this._debugResolveContext,
this._debugLabel,
) : assert(color != null),
assert(darkColor != null),
assert(highContrastColor != null),
assert(darkHighContrastColor != null),
assert(elevatedColor != null),
assert(darkElevatedColor != null),
assert(highContrastElevatedColor != null),
assert(darkHighContrastElevatedColor != null),
assert(_effectiveColor != null),
// The super constructor has to be called with a dummy value in order to mark
) : // The super constructor has to be called with a dummy value in order to mark
// this constructor const.
// The field `value` is overridden in the class implementation.
super(0);
Expand Down Expand Up @@ -908,7 +899,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
/// * [maybeResolve], which is similar to this function, but will allow a
/// null `resolvable` color.
static Color resolve(Color resolvable, BuildContext context) {
assert(context != null);
return (resolvable is CupertinoDynamicColor)
? resolvable.resolveFrom(context)
: resolvable;
Expand All @@ -931,7 +921,6 @@ class CupertinoDynamicColor extends Color with Diagnosticable {
if (resolvable == null) {
return null;
}
assert(context != null);
return (resolvable is CupertinoDynamicColor)
? resolvable.resolveFrom(context)
: resolvable;
Expand Down
15 changes: 5 additions & 10 deletions packages/flutter/lib/src/cupertino/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ class CupertinoContextMenu extends StatefulWidget {
'This feature was deprecated after v3.4.0-34.1.pre.',
)
this.previewBuilder = _defaultPreviewBuilder,
}) : assert(actions != null && actions.isNotEmpty),
assert(child != null),
}) : assert(actions.isNotEmpty),
builder = ((BuildContext context, Animation<double> animation) => child);

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

Expand Down Expand Up @@ -794,8 +793,7 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
super.filter,
required Rect previousChildRect,
super.settings,
}) : assert(actions != null && actions.isNotEmpty),
assert(contextMenuLocation != null),
}) : assert(actions.isNotEmpty),
_actions = actions,
_builder = builder,
_contextMenuLocation = contextMenuLocation,
Expand Down Expand Up @@ -1081,8 +1079,7 @@ class _ContextMenuRouteStatic extends StatefulWidget {
this.onDismiss,
required this.orientation,
this.sheetGlobalKey,
}) : assert(contextMenuLocation != null),
assert(orientation != null);
});

final List<Widget>? actions;
final Widget child;
Expand Down Expand Up @@ -1409,9 +1406,7 @@ class _ContextMenuSheet extends StatelessWidget {
required this.actions,
required _ContextMenuLocation contextMenuLocation,
required Orientation orientation,
}) : assert(actions != null && actions.isNotEmpty),
assert(contextMenuLocation != null),
assert(orientation != null),
}) : assert(actions.isNotEmpty),
_contextMenuLocation = contextMenuLocation,
_orientation = orientation;

Expand Down
4 changes: 1 addition & 3 deletions packages/flutter/lib/src/cupertino/context_menu_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class CupertinoContextMenuAction extends StatefulWidget {
this.isDestructiveAction = false,
this.onPressed,
this.trailingIcon,
}) : assert(child != null),
assert(isDefaultAction != null),
assert(isDestructiveAction != null);
});

/// The widget that will be placed inside the action.
final Widget child;
Expand Down
16 changes: 3 additions & 13 deletions packages/flutter/lib/src/cupertino/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class _DatePickerLayoutDelegate extends MultiChildLayoutDelegate {
_DatePickerLayoutDelegate({
required this.columnWidths,
required this.textDirectionFactor,
}) : assert(columnWidths != null),
assert(textDirectionFactor != null);
});

// The list containing widths of all columns.
final List<double> columnWidths;
Expand Down Expand Up @@ -277,14 +276,10 @@ class CupertinoDatePicker extends StatefulWidget {
this.dateOrder,
this.backgroundColor,
}) : initialDateTime = initialDateTime ?? DateTime.now(),
assert(mode != null),
assert(onDateTimeChanged != null),
assert(minimumYear != null),
assert(
minuteInterval > 0 && 60 % minuteInterval == 0,
'minute interval is not a positive integer factor of 60',
) {
assert(this.initialDateTime != null);
assert(
mode != CupertinoDatePickerMode.dateAndTime || minimumDate == null || !this.initialDateTime.isBefore(minimumDate!),
'initial date is before minimum date',
Expand Down Expand Up @@ -944,7 +939,6 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
}

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

void _scrollToDate(DateTime newDate) {
assert(newDate != null);
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
if (selectedYear != newDate.year) {
_animateColumnControllerToItem(yearController, newDate.year);
Expand Down Expand Up @@ -1551,15 +1544,12 @@ class CupertinoTimerPicker extends StatefulWidget {
this.alignment = Alignment.center,
this.backgroundColor,
required this.onTimerDurationChanged,
}) : assert(mode != null),
assert(onTimerDurationChanged != null),
assert(initialTimerDuration >= Duration.zero),
}) : assert(initialTimerDuration >= Duration.zero),
assert(initialTimerDuration < const Duration(days: 1)),
assert(minuteInterval > 0 && 60 % minuteInterval == 0),
assert(secondInterval > 0 && 60 % secondInterval == 0),
assert(initialTimerDuration.inMinutes % minuteInterval == 0),
assert(initialTimerDuration.inSeconds % secondInterval == 0),
assert(alignment != null);
assert(initialTimerDuration.inSeconds % secondInterval == 0);

/// The mode of the timer picker.
final CupertinoTimerPickerMode mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class CupertinoDesktopTextSelectionToolbarButton extends StatefulWidget {
super.key,
required this.onPressed,
required Widget this.child,
}) : assert(child != null),
buttonItem = null;
}) : buttonItem = null;

/// Create an instance of [CupertinoDesktopTextSelectionToolbarButton] whose child is
/// a [Text] widget styled like the default Mac context menu button.
Expand Down Expand Up @@ -66,8 +65,7 @@ class CupertinoDesktopTextSelectionToolbarButton extends StatefulWidget {
CupertinoDesktopTextSelectionToolbarButton.buttonItem({
super.key,
required ContextMenuButtonItem this.buttonItem,
}) : assert(buttonItem != null),
onPressed = buttonItem.onPressed,
}) : onPressed = buttonItem.onPressed,
child = null;

/// {@macro flutter.cupertino.CupertinoTextSelectionToolbarButton.onPressed}
Expand Down
14 changes: 5 additions & 9 deletions packages/flutter/lib/src/cupertino/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class CupertinoAlertDialog extends StatelessWidget {
this.actionScrollController,
this.insetAnimationDuration = const Duration(milliseconds: 100),
this.insetAnimationCurve = Curves.decelerate,
}) : assert(actions != null);
});

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

/// The callback that is called when the button is tapped.
///
Expand Down Expand Up @@ -701,7 +700,7 @@ class CupertinoActionSheetAction extends StatelessWidget {
}

return MouseRegion(
cursor: onPressed != null && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
cursor: kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
child: GestureDetector(
onTap: onPressed,
behavior: HitTestBehavior.opaque,
Expand Down Expand Up @@ -896,7 +895,6 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
}

void _placeChildInSlot(RenderObject child, _AlertDialogSections slot) {
assert(slot != null);
switch (slot) {
case _AlertDialogSections.contentSection:
renderObject.contentSection = child as RenderBox;
Expand Down Expand Up @@ -1443,7 +1441,7 @@ class _CupertinoAlertActionSection extends StatelessWidget {
this.scrollController,
this.hasCancelButton = false,
this.isActionSheet = false,
}) : assert(children != null);
});

final List<Widget> children;

Expand Down Expand Up @@ -1593,9 +1591,7 @@ class CupertinoDialogAction extends StatelessWidget {
this.isDestructiveAction = false,
this.textStyle,
required this.child,
}) : assert(child != null),
assert(isDefaultAction != null),
assert(isDestructiveAction != null);
});

/// The callback that is called when the button is tapped or otherwise
/// activated.
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter/lib/src/cupertino/interface_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class CupertinoUserInterfaceLevel extends InheritedWidget {
super.key,
required CupertinoUserInterfaceLevelData data,
required super.child,
}) : assert(data != null),
_data = data;
}) : _data = data;

final CupertinoUserInterfaceLevelData _data;

Expand All @@ -65,7 +64,6 @@ class CupertinoUserInterfaceLevel extends InheritedWidget {
/// * [maybeOf], which is similar, but will return null if no
/// [CupertinoUserInterfaceLevel] encloses the given context.
static CupertinoUserInterfaceLevelData of(BuildContext context) {
assert(context != null);
final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType<CupertinoUserInterfaceLevel>();
if (query != null) {
return query._data;
Expand Down Expand Up @@ -95,7 +93,6 @@ class CupertinoUserInterfaceLevel extends InheritedWidget {
/// * [of], which is similar, but will throw an exception if no
/// [CupertinoUserInterfaceLevel] encloses the given context.
static CupertinoUserInterfaceLevelData? maybeOf(BuildContext context) {
assert(context != null);
final CupertinoUserInterfaceLevel? query = context.dependOnInheritedWidgetOfExactType<CupertinoUserInterfaceLevel>();
if (query != null) {
return query._data;
Expand Down
Loading

0 comments on commit 0de8bef

Please sign in to comment.