From 0de8bef744ee3f21504af3570c690a8f045eead2 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 23 Jan 2023 17:36:50 -0800 Subject: [PATCH] Remove unnecessary null checks in flutter/cupertino (#119020) --- .../lib/src/cupertino/activity_indicator.dart | 8 +--- packages/flutter/lib/src/cupertino/app.dart | 16 +------ .../lib/src/cupertino/bottom_tab_bar.dart | 8 +--- .../flutter/lib/src/cupertino/button.dart | 4 -- .../flutter/lib/src/cupertino/colors.dart | 13 +----- .../lib/src/cupertino/context_menu.dart | 15 +++---- .../src/cupertino/context_menu_action.dart | 4 +- .../lib/src/cupertino/date_picker.dart | 16 ++----- ...desktop_text_selection_toolbar_button.dart | 6 +-- .../flutter/lib/src/cupertino/dialog.dart | 14 +++--- .../lib/src/cupertino/interface_level.dart | 5 +-- .../flutter/lib/src/cupertino/nav_bar.dart | 35 +++------------ .../lib/src/cupertino/page_scaffold.dart | 3 +- .../flutter/lib/src/cupertino/picker.dart | 17 ++------ .../flutter/lib/src/cupertino/refresh.dart | 14 ++---- packages/flutter/lib/src/cupertino/route.dart | 43 ++++--------------- .../flutter/lib/src/cupertino/scrollbar.dart | 6 +-- .../lib/src/cupertino/search_field.dart | 9 +--- .../lib/src/cupertino/segmented_control.dart | 9 +--- .../flutter/lib/src/cupertino/slider.dart | 15 ++----- .../cupertino/sliding_segmented_control.dart | 12 +----- .../flutter/lib/src/cupertino/switch.dart | 15 +------ .../lib/src/cupertino/tab_scaffold.dart | 23 +++------- .../flutter/lib/src/cupertino/tab_view.dart | 2 +- .../flutter/lib/src/cupertino/text_field.dart | 40 ++--------------- .../src/cupertino/text_form_field_row.dart | 11 +---- .../src/cupertino/text_selection_toolbar.dart | 15 ++----- .../text_selection_toolbar_button.dart | 6 +-- .../flutter/lib/src/cupertino/text_theme.dart | 3 +- packages/flutter/lib/src/cupertino/theme.dart | 10 ++--- .../lib/src/cupertino/thumb_painter.dart | 2 +- 31 files changed, 80 insertions(+), 319 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/activity_indicator.dart b/packages/flutter/lib/src/cupertino/activity_indicator.dart index 8df6eee0062..bd5bacf6b76 100644 --- a/packages/flutter/lib/src/cupertino/activity_indicator.dart +++ b/packages/flutter/lib/src/cupertino/activity_indicator.dart @@ -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 @@ -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; diff --git a/packages/flutter/lib/src/cupertino/app.dart b/packages/flutter/lib/src/cupertino/app.dart index 849c6486814..8aface4f807 100644 --- a/packages/flutter/lib/src/cupertino/app.dart +++ b/packages/flutter/lib/src/cupertino/app.dart @@ -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, @@ -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, diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index 5dc70c3665c..209a18a2aa6 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -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. /// diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index 64a5056592d..b5f71d54b9b 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -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. @@ -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; diff --git a/packages/flutter/lib/src/cupertino/colors.dart b/packages/flutter/lib/src/cupertino/colors.dart index 5907e5f8654..18fd90b1098 100644 --- a/packages/flutter/lib/src/cupertino/colors.dart +++ b/packages/flutter/lib/src/cupertino/colors.dart @@ -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); @@ -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; @@ -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; diff --git a/packages/flutter/lib/src/cupertino/context_menu.dart b/packages/flutter/lib/src/cupertino/context_menu.dart index 5a6024b0936..1545c73b3c6 100644 --- a/packages/flutter/lib/src/cupertino/context_menu.dart +++ b/packages/flutter/lib/src/cupertino/context_menu.dart @@ -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 animation) => child); /// Creates a context menu with a custom [builder] controlling the widget. @@ -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; @@ -794,8 +793,7 @@ class _ContextMenuRoute extends PopupRoute { super.filter, required Rect previousChildRect, super.settings, - }) : assert(actions != null && actions.isNotEmpty), - assert(contextMenuLocation != null), + }) : assert(actions.isNotEmpty), _actions = actions, _builder = builder, _contextMenuLocation = contextMenuLocation, @@ -1081,8 +1079,7 @@ class _ContextMenuRouteStatic extends StatefulWidget { this.onDismiss, required this.orientation, this.sheetGlobalKey, - }) : assert(contextMenuLocation != null), - assert(orientation != null); + }); final List? actions; final Widget child; @@ -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; diff --git a/packages/flutter/lib/src/cupertino/context_menu_action.dart b/packages/flutter/lib/src/cupertino/context_menu_action.dart index 3cd258becfa..4c26071f2b2 100644 --- a/packages/flutter/lib/src/cupertino/context_menu_action.dart +++ b/packages/flutter/lib/src/cupertino/context_menu_action.dart @@ -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; diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index 579ca40105b..d152613729f 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -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 columnWidths; @@ -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', @@ -944,7 +939,6 @@ class _CupertinoDatePickerDateTimeState extends State { } 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); @@ -1349,7 +1343,6 @@ class _CupertinoDatePickerDateState extends State { } void _scrollToDate(DateTime newDate) { - assert(newDate != null); SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) { if (selectedYear != newDate.year) { _animateColumnControllerToItem(yearController, newDate.year); @@ -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; diff --git a/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart b/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart index b035f622ec8..677530c1340 100644 --- a/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart +++ b/packages/flutter/lib/src/cupertino/desktop_text_selection_toolbar_button.dart @@ -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. @@ -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} diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index 6735f5c5419..4d32891b0e5 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -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. @@ -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. /// @@ -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, @@ -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; @@ -1443,7 +1441,7 @@ class _CupertinoAlertActionSection extends StatelessWidget { this.scrollController, this.hasCancelButton = false, this.isActionSheet = false, - }) : assert(children != null); + }); final List children; @@ -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. diff --git a/packages/flutter/lib/src/cupertino/interface_level.dart b/packages/flutter/lib/src/cupertino/interface_level.dart index 58ffe5fb80b..e4de7829a17 100644 --- a/packages/flutter/lib/src/cupertino/interface_level.dart +++ b/packages/flutter/lib/src/cupertino/interface_level.dart @@ -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; @@ -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(); if (query != null) { return query._data; @@ -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(); if (query != null) { return query._data; diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index a1395cdf75f..88bb34b368f 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -257,15 +257,7 @@ class CupertinoNavigationBar extends StatefulWidget implements ObstructingPrefer this.padding, this.transitionBetweenRoutes = true, this.heroTag = _defaultHeroTag, - }) : assert(automaticallyImplyLeading != null), - assert(automaticallyImplyMiddle != null), - assert(transitionBetweenRoutes != null), - assert( - heroTag != null, - 'heroTag cannot be null. Use transitionBetweenRoutes = false to ' - 'disable Hero transition on this navigation bar.', - ), - assert( + }) : assert( !transitionBetweenRoutes || identical(heroTag, _defaultHeroTag), 'Cannot specify a heroTag override if this navigation bar does not ' 'transition due to transitionBetweenRoutes = false.', @@ -599,9 +591,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget { this.transitionBetweenRoutes = true, this.heroTag = _defaultHeroTag, this.stretch = false, - }) : assert(automaticallyImplyLeading != null), - assert(automaticallyImplyTitle != null), - assert( + }) : assert( automaticallyImplyTitle == true || largeTitle != null, 'No largeTitle has been provided but automaticallyImplyTitle is also ' 'false. Either provide a largeTitle or set automaticallyImplyTitle to ' @@ -781,9 +771,7 @@ class _LargeTitleNavigationBarSliverDelegate required this.persistentHeight, required this.alwaysShowMiddle, required this.stretchConfiguration, - }) : assert(persistentHeight != null), - assert(alwaysShowMiddle != null), - assert(transitionBetweenRoutes != null); + }); final _NavigationBarStaticComponentsKeys keys; final _NavigationBarStaticComponents components; @@ -1626,9 +1614,7 @@ class _TransitionableNavigationBar extends StatelessWidget { required this.hasUserMiddle, required this.largeExpanded, required this.child, - }) : assert(componentsKeys != null), - assert(largeExpanded != null), - assert(!largeExpanded || largeTitleTextStyle != null), + }) : assert(!largeExpanded || largeTitleTextStyle != null), super(key: componentsKeys.navBarBoxKey); final _NavigationBarStaticComponentsKeys componentsKeys; @@ -2100,7 +2086,7 @@ class _NavigationBarComponentsTransition { return null; } - if (bottomLargeTitle != null && topBackLabel != null) { + if (topBackLabel != null) { // Move from current position to the top page's back label position. return slideFromLeadingEdge( fromKey: bottomComponents.largeTitleKey, @@ -2127,7 +2113,7 @@ class _NavigationBarComponentsTransition { ); } - if (bottomLargeTitle != null && topLeading != null) { + if (topLeading != null) { // Unlike bottom middle, the bottom large title moves when it can't // transition to the top back label position. final RelativeRect from = positionInTransitionBox(bottomComponents.largeTitleKey, from: bottomNavBarBox); @@ -2258,7 +2244,6 @@ class _NavigationBarComponentsTransition { // text is too long, the topBackLabel will say 'Back' instead of the original // text. if (bottomLargeTitle != null && - topBackLabel != null && bottomLargeExpanded) { return slideFromLeadingEdge( fromKey: bottomComponents.largeTitleKey, @@ -2282,7 +2267,7 @@ class _NavigationBarComponentsTransition { // The topBackLabel always comes from the large title first if available // and expanded instead of middle. - if (bottomMiddle != null && topBackLabel != null) { + if (bottomMiddle != null) { return slideFromLeadingEdge( fromKey: bottomComponents.middleKey, fromNavBarBox: bottomNavBarBox, @@ -2452,10 +2437,6 @@ Widget _navBarHeroFlightShuttleBuilder( BuildContext fromHeroContext, BuildContext toHeroContext, ) { - assert(animation != null); - assert(flightDirection != null); - assert(fromHeroContext != null); - assert(toHeroContext != null); assert(fromHeroContext.widget is Hero); assert(toHeroContext.widget is Hero); @@ -2468,8 +2449,6 @@ Widget _navBarHeroFlightShuttleBuilder( final _TransitionableNavigationBar fromNavBar = fromHeroWidget.child as _TransitionableNavigationBar; final _TransitionableNavigationBar toNavBar = toHeroWidget.child as _TransitionableNavigationBar; - assert(fromNavBar.componentsKeys != null); - assert(toNavBar.componentsKeys != null); assert( fromNavBar.componentsKeys.navBarBoxKey.currentContext!.owner != null, diff --git a/packages/flutter/lib/src/cupertino/page_scaffold.dart b/packages/flutter/lib/src/cupertino/page_scaffold.dart index 983cac302c2..db42ae8925f 100644 --- a/packages/flutter/lib/src/cupertino/page_scaffold.dart +++ b/packages/flutter/lib/src/cupertino/page_scaffold.dart @@ -39,8 +39,7 @@ class CupertinoPageScaffold extends StatefulWidget { this.backgroundColor, this.resizeToAvoidBottomInset = true, required this.child, - }) : assert(child != null), - assert(resizeToAvoidBottomInset != null); + }); /// The [navigationBar], typically a [CupertinoNavigationBar], is drawn at the /// top of the screen. diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart index 232644ed56e..71e23e2dc6f 100644 --- a/packages/flutter/lib/src/cupertino/picker.dart +++ b/packages/flutter/lib/src/cupertino/picker.dart @@ -83,13 +83,9 @@ class CupertinoPicker extends StatefulWidget { required List children, this.selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(), bool looping = false, - }) : assert(children != null), - assert(diameterRatio != null), - assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), assert(magnification > 0), - assert(itemExtent != null), assert(itemExtent > 0), - assert(squeeze != null), assert(squeeze > 0), childDelegate = looping ? ListWheelChildLoopingListDelegate(children: children) @@ -126,13 +122,9 @@ class CupertinoPicker extends StatefulWidget { required NullableIndexedWidgetBuilder itemBuilder, int? childCount, this.selectionOverlay = const CupertinoPickerDefaultSelectionOverlay(), - }) : assert(itemBuilder != null), - assert(diameterRatio != null), - assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), + }) : assert(diameterRatio > 0.0, RenderListWheelViewport.diameterRatioZeroMessage), assert(magnification > 0), - assert(itemExtent != null), assert(itemExtent > 0), - assert(squeeze != null), assert(squeeze > 0), childDelegate = ListWheelChildBuilderDelegate(builder: itemBuilder, childCount: childCount); @@ -254,7 +246,6 @@ class _CupertinoPickerState extends State { hasSuitableHapticHardware = false; break; } - assert(hasSuitableHapticHardware != null); if (hasSuitableHapticHardware && index != _lastHapticIndex) { _lastHapticIndex = index; HapticFeedback.selectionClick(); @@ -355,9 +346,7 @@ class CupertinoPickerDefaultSelectionOverlay extends StatelessWidget { this.background = CupertinoColors.tertiarySystemFill, this.capStartEdge = true, this.capEndEdge = true, - }) : assert(background != null), - assert(capStartEdge != null), - assert(capEndEdge != null); + }); /// Whether to use the default use rounded corners and margin on the start side. final bool capStartEdge; diff --git a/packages/flutter/lib/src/cupertino/refresh.dart b/packages/flutter/lib/src/cupertino/refresh.dart index d98e516dcbd..b9e528c4366 100644 --- a/packages/flutter/lib/src/cupertino/refresh.dart +++ b/packages/flutter/lib/src/cupertino/refresh.dart @@ -20,9 +20,7 @@ class _CupertinoSliverRefresh extends SingleChildRenderObjectWidget { this.refreshIndicatorLayoutExtent = 0.0, this.hasLayoutExtent = false, super.child, - }) : assert(refreshIndicatorLayoutExtent != null), - assert(refreshIndicatorLayoutExtent >= 0.0), - assert(hasLayoutExtent != null); + }) : assert(refreshIndicatorLayoutExtent >= 0.0); // The amount of space the indicator should occupy in the sliver in a // resting state when in the refreshing mode. @@ -61,9 +59,7 @@ class _RenderCupertinoSliverRefresh extends RenderSliver required double refreshIndicatorExtent, required bool hasLayoutExtent, RenderBox? child, - }) : assert(refreshIndicatorExtent != null), - assert(refreshIndicatorExtent >= 0.0), - assert(hasLayoutExtent != null), + }) : assert(refreshIndicatorExtent >= 0.0), _refreshIndicatorExtent = refreshIndicatorExtent, _hasLayoutExtent = hasLayoutExtent { this.child = child; @@ -74,7 +70,6 @@ class _RenderCupertinoSliverRefresh extends RenderSliver double get refreshIndicatorLayoutExtent => _refreshIndicatorExtent; double _refreshIndicatorExtent; set refreshIndicatorLayoutExtent(double value) { - assert(value != null); assert(value >= 0.0); if (value == _refreshIndicatorExtent) { return; @@ -89,7 +84,6 @@ class _RenderCupertinoSliverRefresh extends RenderSliver bool get hasLayoutExtent => _hasLayoutExtent; bool _hasLayoutExtent; set hasLayoutExtent(bool value) { - assert(value != null); if (value == _hasLayoutExtent) { return; } @@ -303,9 +297,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget { this.refreshIndicatorExtent = _defaultRefreshIndicatorExtent, this.builder = buildRefreshIndicator, this.onRefresh, - }) : assert(refreshTriggerPullDistance != null), - assert(refreshTriggerPullDistance > 0.0), - assert(refreshIndicatorExtent != null), + }) : assert(refreshTriggerPullDistance > 0.0), assert(refreshIndicatorExtent >= 0.0), assert( refreshTriggerPullDistance >= refreshIndicatorExtent, diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 071e787c352..7ea9976c8f1 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -225,21 +225,11 @@ mixin CupertinoRouteTransitionMixin on PageRoute { @override Widget buildPage(BuildContext context, Animation animation, Animation secondaryAnimation) { final Widget child = buildContent(context); - final Widget result = Semantics( + return Semantics( scopesRoute: true, explicitChildNodes: true, child: child, ); - assert(() { - if (child == null) { - throw FlutterError.fromParts([ - ErrorSummary('The builder for route "${settings.name}" returned null.'), - ErrorDescription('Route builders must never return null.'), - ]); - } - return true; - }()); - return result; } // Called by _CupertinoBackGestureDetector when a pop ("back") drag start @@ -343,9 +333,7 @@ class CupertinoPageRoute extends PageRoute with CupertinoRouteTransitionMi this.maintainState = true, super.fullscreenDialog, super.allowSnapshotting = true, - }) : assert(builder != null), - assert(maintainState != null), - assert(fullscreenDialog != null) { + }) { assert(opaque); } @@ -373,8 +361,7 @@ class _PageBasedCupertinoPageRoute extends PageRoute with CupertinoRouteTr _PageBasedCupertinoPageRoute({ required CupertinoPage page, super.allowSnapshotting = true, - }) : assert(page != null), - super(settings: page) { + }) : super(settings: page) { assert(opaque); } @@ -424,9 +411,7 @@ class CupertinoPage extends Page { super.name, super.arguments, super.restorationId, - }) : assert(child != null), - assert(maintainState != null), - assert(fullscreenDialog != null); + }); /// The content to be shown in the [Route] created by this page. final Widget child; @@ -468,8 +453,7 @@ class CupertinoPageTransition extends StatelessWidget { required Animation secondaryRouteAnimation, required this.child, required bool linearTransition, - }) : assert(linearTransition != null), - _primaryPositionAnimation = + }) : _primaryPositionAnimation = (linearTransition ? primaryRouteAnimation : CurvedAnimation( @@ -607,9 +591,7 @@ class _CupertinoBackGestureDetector extends StatefulWidget { required this.enabledCallback, required this.onStartPopGesture, required this.child, - }) : assert(enabledCallback != null), - assert(onStartPopGesture != null), - assert(child != null); + }); final Widget child; @@ -731,8 +713,7 @@ class _CupertinoBackGestureController { _CupertinoBackGestureController({ required this.navigator, required this.controller, - }) : assert(navigator != null), - assert(controller != null) { + }) { navigator.didStartUserGesture(); } @@ -854,7 +835,6 @@ class _CupertinoEdgeShadowDecoration extends Decoration { _CupertinoEdgeShadowDecoration? b, double t, ) { - assert(t != null); if (a == null && b == null) { return null; } @@ -921,8 +901,7 @@ class _CupertinoEdgeShadowPainter extends BoxPainter { _CupertinoEdgeShadowPainter( this._decoration, super.onChange, - ) : assert(_decoration != null), - assert(_decoration._colors == null || _decoration._colors!.length > 1); + ) : assert(_decoration._colors == null || _decoration._colors!.length > 1); final _CupertinoEdgeShadowDecoration _decoration; @@ -1192,7 +1171,6 @@ Future showCupertinoModalPopup({ RouteSettings? routeSettings, Offset? anchorPoint, }) { - assert(useRootNavigator != null); return Navigator.of(context, rootNavigator: useRootNavigator).push( CupertinoModalPopupRoute( builder: builder, @@ -1297,8 +1275,6 @@ Future showCupertinoDialog({ RouteSettings? routeSettings, Offset? anchorPoint, }) { - assert(builder != null); - assert(useRootNavigator != null); return Navigator.of(context, rootNavigator: useRootNavigator).push(CupertinoDialogRoute( builder: builder, @@ -1361,8 +1337,7 @@ class CupertinoDialogRoute extends RawDialogRoute { super.transitionBuilder = _buildCupertinoDialogTransitions, super.settings, super.anchorPoint, - }) : assert(barrierDismissible != null), - super( + }) : super( pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { return builder(context); }, diff --git a/packages/flutter/lib/src/cupertino/scrollbar.dart b/packages/flutter/lib/src/cupertino/scrollbar.dart index 1b847f24991..42856ca8406 100644 --- a/packages/flutter/lib/src/cupertino/scrollbar.dart +++ b/packages/flutter/lib/src/cupertino/scrollbar.dart @@ -87,12 +87,8 @@ class CupertinoScrollbar extends RawScrollbar { 'This feature was deprecated after v2.9.0-1.0.pre.', ) bool? isAlwaysShown, - }) : assert(thickness != null), - assert(thickness < double.infinity), - assert(thicknessWhileDragging != null), + }) : assert(thickness < double.infinity), assert(thicknessWhileDragging < double.infinity), - assert(radius != null), - assert(radiusWhileDragging != null), assert( isAlwaysShown == null || thumbVisibility == null, 'Scrollbar thumb appearance should only be controlled with thumbVisibility, ' diff --git a/packages/flutter/lib/src/cupertino/search_field.dart b/packages/flutter/lib/src/cupertino/search_field.dart index cc876fdbb24..348132406f1 100644 --- a/packages/flutter/lib/src/cupertino/search_field.dart +++ b/packages/flutter/lib/src/cupertino/search_field.dart @@ -126,14 +126,7 @@ class CupertinoSearchTextField extends StatefulWidget { this.onTap, this.autocorrect = true, this.enabled, - }) : assert(padding != null), - assert(itemColor != null), - assert(itemSize != null), - assert(prefixInsets != null), - assert(suffixInsets != null), - assert(suffixIcon != null), - assert(suffixMode != null), - assert( + }) : assert( !((decoration != null) && (backgroundColor != null)), 'Cannot provide both a background color and a decoration\n' 'To provide both, use "decoration: BoxDecoration(color: ' diff --git a/packages/flutter/lib/src/cupertino/segmented_control.dart b/packages/flutter/lib/src/cupertino/segmented_control.dart index d381128d927..aedd6468119 100644 --- a/packages/flutter/lib/src/cupertino/segmented_control.dart +++ b/packages/flutter/lib/src/cupertino/segmented_control.dart @@ -99,9 +99,7 @@ class CupertinoSegmentedControl extends StatefulWidget { this.borderColor, this.pressedColor, this.padding, - }) : assert(children != null), - assert(children.length >= 2), - assert(onValueChanged != null), + }) : assert(children.length >= 2), assert( groupValue == null || children.keys.any((T child) => child == groupValue), 'The groupValue must be either null or one of the keys in the children map.', @@ -458,8 +456,7 @@ class _RenderSegmentedControl extends RenderBox required TextDirection textDirection, required List backgroundColors, required Color borderColor, - }) : assert(textDirection != null), - _textDirection = textDirection, + }) : _textDirection = textDirection, _selectedIndex = selectedIndex, _pressedIndex = pressedIndex, _backgroundColors = backgroundColors, @@ -685,7 +682,6 @@ class _RenderSegmentedControl extends RenderBox } void _paintChild(PaintingContext context, Offset offset, RenderBox child, int childIndex) { - assert(child != null); final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; @@ -708,7 +704,6 @@ class _RenderSegmentedControl extends RenderBox @override bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { - assert(position != null); RenderBox? child = lastChild; while (child != null) { final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; diff --git a/packages/flutter/lib/src/cupertino/slider.dart b/packages/flutter/lib/src/cupertino/slider.dart index 768ccbfe9a8..73a4b523cc8 100644 --- a/packages/flutter/lib/src/cupertino/slider.dart +++ b/packages/flutter/lib/src/cupertino/slider.dart @@ -71,12 +71,8 @@ class CupertinoSlider extends StatefulWidget { this.divisions, this.activeColor, this.thumbColor = CupertinoColors.white, - }) : assert(value != null), - assert(min != null), - assert(max != null), - assert(value >= min && value <= max), - assert(divisions == null || divisions > 0), - assert(thumbColor != null); + }) : assert(value >= min && value <= max), + assert(divisions == null || divisions > 0); /// The currently selected value for this slider. /// @@ -337,9 +333,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements MouseTracke required TickerProvider vsync, required TextDirection textDirection, MouseCursor cursor = MouseCursor.defer, - }) : assert(value != null && value >= 0.0 && value <= 1.0), - assert(textDirection != null), - assert(cursor != null), + }) : assert(value >= 0.0 && value <= 1.0), _cursor = cursor, _value = value, _divisions = divisions, @@ -363,7 +357,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements MouseTracke double get value => _value; double _value; set value(double newValue) { - assert(newValue != null && newValue >= 0.0 && newValue <= 1.0); + assert(newValue >= 0.0 && newValue <= 1.0); if (newValue == _value) { return; } @@ -435,7 +429,6 @@ class _RenderCupertinoSlider extends RenderConstrainedBox implements MouseTracke TextDirection get textDirection => _textDirection; TextDirection _textDirection; set textDirection(TextDirection value) { - assert(value != null); if (_textDirection == value) { return; } diff --git a/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart b/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart index ab3be16440e..2c9365722be 100644 --- a/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart +++ b/packages/flutter/lib/src/cupertino/sliding_segmented_control.dart @@ -320,10 +320,7 @@ class CupertinoSlidingSegmentedControl extends StatefulWidget { this.thumbColor = _kThumbColor, this.padding = _kHorizontalItemPadding, this.backgroundColor = CupertinoColors.tertiarySystemFill, - }) : assert(children != null), - assert(children.length >= 2), - assert(padding != null), - assert(onValueChanged != null), + }) : assert(children.length >= 2), assert( groupValue == null || children.keys.contains(groupValue), 'The groupValue must be either null or one of the keys in the children map.', @@ -523,7 +520,6 @@ class _SegmentedControlState extends State( begin: thumbScaleAnimation.value, @@ -793,8 +789,7 @@ class _RenderSegmentedControl extends RenderBox required this.state, }) : _highlightedIndex = highlightedIndex, _thumbColor = thumbColor, - _thumbScale = thumbScale, - assert(state != null); + _thumbScale = thumbScale; final _SegmentedControlState state; @@ -1074,13 +1069,11 @@ class _RenderSegmentedControl extends RenderBox // Paint the separator to the right of the given child. final Paint separatorPaint = Paint(); void _paintSeparator(PaintingContext context, Offset offset, RenderBox child) { - assert(child != null); final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; context.paintChild(child, offset + childParentData.offset); } void _paintChild(PaintingContext context, Offset offset, RenderBox child) { - assert(child != null); final _SegmentedControlContainerBoxParentData childParentData = child.parentData! as _SegmentedControlContainerBoxParentData; context.paintChild(child, childParentData.offset + offset); } @@ -1119,7 +1112,6 @@ class _RenderSegmentedControl extends RenderBox @override bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { - assert(position != null); RenderBox? child = lastChild; while (child != null) { final _SegmentedControlContainerBoxParentData childParentData = diff --git a/packages/flutter/lib/src/cupertino/switch.dart b/packages/flutter/lib/src/cupertino/switch.dart index 095a3285aba..e7d5a27de70 100644 --- a/packages/flutter/lib/src/cupertino/switch.dart +++ b/packages/flutter/lib/src/cupertino/switch.dart @@ -76,8 +76,7 @@ class CupertinoSwitch extends StatefulWidget { this.applyTheme, this.focusColor, this.dragStartBehavior = DragStartBehavior.start, - }) : assert(value != null), - assert(dragStartBehavior != null); + }); /// Whether this switch is on or off. /// @@ -473,10 +472,7 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { required TextDirection textDirection, required bool isFocused, required _CupertinoSwitchState state, - }) : assert(value != null), - assert(activeColor != null), - assert(state != null), - _value = value, + }) : _value = value, _activeColor = activeColor, _trackColor = trackColor, _focusColor = focusColor, @@ -495,7 +491,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { bool get value => _value; bool _value; set value(bool value) { - assert(value != null); if (value == _value) { return; } @@ -506,7 +501,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { Color get activeColor => _activeColor; Color _activeColor; set activeColor(Color value) { - assert(value != null); if (value == _activeColor) { return; } @@ -517,7 +511,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { Color get trackColor => _trackColor; Color _trackColor; set trackColor(Color value) { - assert(value != null); if (value == _trackColor) { return; } @@ -528,7 +521,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { Color get thumbColor => _thumbPainter.color; CupertinoThumbPainter _thumbPainter; set thumbColor(Color value) { - assert(value != null); if (value == thumbColor) { return; } @@ -539,7 +531,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { Color get focusColor => _focusColor; Color _focusColor; set focusColor(Color value) { - assert(value != null); if (value == _focusColor) { return; } @@ -564,7 +555,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { TextDirection get textDirection => _textDirection; TextDirection _textDirection; set textDirection(TextDirection value) { - assert(value != null); if (_textDirection == value) { return; } @@ -575,7 +565,6 @@ class _RenderCupertinoSwitch extends RenderConstrainedBox { bool get isFocused => _isFocused; bool _isFocused; set isFocused(bool value) { - assert(value != null); if(value == _isFocused) { return; } diff --git a/packages/flutter/lib/src/cupertino/tab_scaffold.dart b/packages/flutter/lib/src/cupertino/tab_scaffold.dart index 509d3e272ca..056cf18ef96 100644 --- a/packages/flutter/lib/src/cupertino/tab_scaffold.dart +++ b/packages/flutter/lib/src/cupertino/tab_scaffold.dart @@ -36,7 +36,6 @@ class CupertinoTabController extends ChangeNotifier { /// greater than or equal to 0, and less than the total number of tabs. CupertinoTabController({ int initialIndex = 0 }) : _index = initialIndex, - assert(initialIndex != null), assert(initialIndex >= 0); bool _isDisposed = false; @@ -52,7 +51,6 @@ class CupertinoTabController extends ChangeNotifier { int get index => _index; int _index; set index(int value) { - assert(value != null); assert(value >= 0); if (_index == value) { return; @@ -135,9 +133,7 @@ class CupertinoTabScaffold extends StatefulWidget { this.backgroundColor, this.resizeToAvoidBottomInset = true, this.restorationId, - }) : assert(tabBar != null), - assert(tabBuilder != null), - assert( + }) : assert( controller == null || controller.index < tabBar.items.length, "The CupertinoTabController's current index ${controller.index} is " 'out of bounds for the tab bar with ${tabBar.items.length} tabs', @@ -324,12 +320,10 @@ class _CupertinoTabScaffoldState extends State with Restor contentPadding = EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom); } - if (widget.tabBar != null && - // Only pad the content with the height of the tab bar if the tab - // isn't already entirely obstructed by a keyboard or other view insets. - // Don't double pad. - (!widget.resizeToAvoidBottomInset || - widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom)) { + // Only pad the content with the height of the tab bar if the tab + // isn't already entirely obstructed by a keyboard or other view insets. + // Don't double pad. + if (!widget.resizeToAvoidBottomInset || widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom) { // TODO(xster): Use real size after partial layout instead of preferred size. // https://github.com/flutter/flutter/issues/12912 final double bottomPadding = @@ -406,9 +400,7 @@ class _TabSwitchingView extends StatefulWidget { required this.currentTabIndex, required this.tabCount, required this.tabBuilder, - }) : assert(currentTabIndex != null), - assert(tabCount != null && tabCount > 0), - assert(tabBuilder != null); + }) : assert(tabCount > 0); final int currentTabIndex; final int tabCount; @@ -530,8 +522,7 @@ class RestorableCupertinoTabController extends RestorableChangeNotifier= 0), + : assert(initialIndex >= 0), _initialIndex = initialIndex; final int _initialIndex; diff --git a/packages/flutter/lib/src/cupertino/tab_view.dart b/packages/flutter/lib/src/cupertino/tab_view.dart index 3d5948a9c1b..0d8c70a3cbc 100644 --- a/packages/flutter/lib/src/cupertino/tab_view.dart +++ b/packages/flutter/lib/src/cupertino/tab_view.dart @@ -50,7 +50,7 @@ class CupertinoTabView extends StatefulWidget { this.onUnknownRoute, this.navigatorObservers = const [], this.restorationScopeId, - }) : assert(navigatorObservers != null); + }); /// The widget builder for the default route of the tab view /// ([Navigator.defaultRouteName], which is `/`). diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 72508e3d02b..98ab4ccbdaa 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -281,35 +281,21 @@ class CupertinoTextField extends StatefulWidget { this.contextMenuBuilder = _defaultContextMenuBuilder, this.spellCheckConfiguration, this.magnifierConfiguration, - }) : assert(textAlign != null), - assert(readOnly != null), - assert(autofocus != null), - assert(obscuringCharacter != null && obscuringCharacter.length == 1), - assert(obscureText != null), - assert(autocorrect != null), + }) : assert(obscuringCharacter.length == 1), smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), - assert(enableSuggestions != null), - assert(scrollPadding != null), - assert(dragStartBehavior != null), - assert(selectionHeightStyle != null), - assert(selectionWidthStyle != null), assert(maxLines == null || maxLines > 0), assert(minLines == null || minLines > 0), assert( (maxLines == null) || (minLines == null) || (maxLines >= minLines), "minLines can't be greater than maxLines", ), - assert(expands != null), assert( !expands || (maxLines == null && minLines == null), 'minLines and maxLines must be null when expands is true.', ), assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), assert(maxLength == null || maxLength > 0), - assert(clearButtonMode != null), - assert(prefixMode != null), - assert(suffixMode != null), // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set. assert( !identical(textInputAction, TextInputAction.newline) || @@ -317,7 +303,6 @@ class CupertinoTextField extends StatefulWidget { !identical(keyboardType, TextInputType.text), 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.', ), - assert(enableIMEPersonalizedLearning != null), keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText); @@ -425,35 +410,21 @@ class CupertinoTextField extends StatefulWidget { this.contextMenuBuilder = _defaultContextMenuBuilder, this.spellCheckConfiguration, this.magnifierConfiguration, - }) : assert(textAlign != null), - assert(readOnly != null), - assert(autofocus != null), - assert(obscuringCharacter != null && obscuringCharacter.length == 1), - assert(obscureText != null), - assert(autocorrect != null), + }) : assert(obscuringCharacter.length == 1), smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), - assert(enableSuggestions != null), - assert(scrollPadding != null), - assert(dragStartBehavior != null), - assert(selectionHeightStyle != null), - assert(selectionWidthStyle != null), assert(maxLines == null || maxLines > 0), assert(minLines == null || minLines > 0), assert( (maxLines == null) || (minLines == null) || (maxLines >= minLines), "minLines can't be greater than maxLines", ), - assert(expands != null), assert( !expands || (maxLines == null && minLines == null), 'minLines and maxLines must be null when expands is true.', ), assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), assert(maxLength == null || maxLength > 0), - assert(clearButtonMode != null), - assert(prefixMode != null), - assert(suffixMode != null), // Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set. assert( !identical(textInputAction, TextInputAction.newline) || @@ -461,8 +432,6 @@ class CupertinoTextField extends StatefulWidget { !identical(keyboardType, TextInputType.text), 'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.', ), - assert(clipBehavior != null), - assert(enableIMEPersonalizedLearning != null), keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText); @@ -1102,9 +1071,6 @@ class _CupertinoTextFieldState extends State with Restoratio } Widget _addTextDependentAttachments(Widget editableText, TextStyle textStyle, TextStyle placeholderStyle) { - assert(editableText != null); - assert(textStyle != null); - assert(placeholderStyle != null); // If there are no surrounding widgets, just return the core editable text // part. if (!_hasDecoration) { @@ -1267,7 +1233,7 @@ class _CupertinoTextFieldState extends State with Restoratio ? side : side.copyWith(color: CupertinoDynamicColor.resolve(side.color, context)); } - resolvedBorder = border == null || border.runtimeType != Border + resolvedBorder = border.runtimeType != Border ? border : Border( top: resolveBorderSide(border.top), diff --git a/packages/flutter/lib/src/cupertino/text_form_field_row.dart b/packages/flutter/lib/src/cupertino/text_form_field_row.dart index 9a8ca8600fb..268d8c06125 100644 --- a/packages/flutter/lib/src/cupertino/text_form_field_row.dart +++ b/packages/flutter/lib/src/cupertino/text_form_field_row.dart @@ -158,28 +158,19 @@ class CupertinoTextFormFieldRow extends FormField { ), EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder, }) : assert(initialValue == null || controller == null), - assert(textAlign != null), - assert(autofocus != null), - assert(readOnly != null), - assert(obscuringCharacter != null && obscuringCharacter.length == 1), - assert(obscureText != null), - assert(autocorrect != null), - assert(enableSuggestions != null), - assert(scrollPadding != null), + assert(obscuringCharacter.length == 1), assert(maxLines == null || maxLines > 0), assert(minLines == null || minLines > 0), assert( (maxLines == null) || (minLines == null) || (maxLines >= minLines), "minLines can't be greater than maxLines", ), - assert(expands != null), assert( !expands || (maxLines == null && minLines == null), 'minLines and maxLines must be null when expands is true.', ), assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'), assert(maxLength == null || maxLength > 0), - assert(enableInteractiveSelection != null), super( initialValue: controller?.text ?? initialValue ?? '', builder: (FormFieldState field) { diff --git a/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart b/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart index 9537dfedd02..bee18a8648a 100644 --- a/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart +++ b/packages/flutter/lib/src/cupertino/text_selection_toolbar.dart @@ -426,8 +426,7 @@ class _CupertinoTextSelectionToolbarContent extends StatefulWidget { required this.isAbove, required this.toolbarBuilder, required this.children, - }) : assert(children != null), - assert(children.length > 0); + }) : assert(children.length > 0); final Offset anchor; final List children; @@ -533,13 +532,7 @@ class _CupertinoTextSelectionToolbarItems extends RenderObjectWidget { required this.dividerWidth, required this.nextButton, required this.nextButtonDisabled, - }) : assert(children != null), - assert(children.isNotEmpty), - assert(backButton != null), - assert(dividerWidth != null), - assert(nextButton != null), - assert(nextButtonDisabled != null), - assert(page != null); + }) : assert(children.isNotEmpty); final Widget backButton; final List children; @@ -732,9 +725,7 @@ class _RenderCupertinoTextSelectionToolbarItems extends RenderBox with Container _RenderCupertinoTextSelectionToolbarItems({ required double dividerWidth, required int page, - }) : assert(dividerWidth != null), - assert(page != null), - _dividerWidth = dividerWidth, + }) : _dividerWidth = dividerWidth, _page = page, super(); diff --git a/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart b/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart index 389d65c7e52..aa0550ec911 100644 --- a/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart +++ b/packages/flutter/lib/src/cupertino/text_selection_toolbar_button.dart @@ -42,8 +42,7 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { super.key, this.onPressed, required Widget this.child, - }) : assert(child != null), - text = null, + }) : text = null, buttonItem = null; /// Create an instance of [CupertinoTextSelectionToolbarButton] whose child is @@ -62,8 +61,7 @@ class CupertinoTextSelectionToolbarButton extends StatelessWidget { CupertinoTextSelectionToolbarButton.buttonItem({ super.key, required ContextMenuButtonItem this.buttonItem, - }) : assert(buttonItem != null), - child = null, + }) : child = null, text = null, onPressed = buttonItem.onPressed; diff --git a/packages/flutter/lib/src/cupertino/text_theme.dart b/packages/flutter/lib/src/cupertino/text_theme.dart index 2ea7fecb0d4..33f797bae5c 100644 --- a/packages/flutter/lib/src/cupertino/text_theme.dart +++ b/packages/flutter/lib/src/cupertino/text_theme.dart @@ -268,8 +268,7 @@ class _TextThemeDefaultsBuilder { const _TextThemeDefaultsBuilder( this.labelColor, this.inactiveGrayColor, - ) : assert(labelColor != null), - assert(inactiveGrayColor != null); + ); final Color labelColor; final Color inactiveGrayColor; diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index 57e08042109..39048b35431 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -53,8 +53,7 @@ class CupertinoTheme extends StatelessWidget { super.key, required this.data, required this.child, - }) : assert(child != null), - assert(data != null); + }); /// The [CupertinoThemeData] styling for this theme. final CupertinoThemeData data; @@ -137,7 +136,7 @@ class _InheritedCupertinoTheme extends InheritedWidget { const _InheritedCupertinoTheme({ required this.theme, required super.child, - }) : assert(theme != null); + }); final CupertinoTheme theme; @@ -528,7 +527,6 @@ class _CupertinoTextThemeDefaults { } CupertinoTextThemeData createDefaults({ required Color primaryColor }) { - assert(primaryColor != null); return _DefaultCupertinoTextThemeData( primaryColor: primaryColor, labelColor: labelColor, @@ -545,9 +543,7 @@ class _DefaultCupertinoTextThemeData extends CupertinoTextThemeData { required this.labelColor, required this.inactiveGray, required super.primaryColor, - }) : assert(labelColor != null), - assert(inactiveGray != null), - assert(primaryColor != null); + }); final Color labelColor; final Color inactiveGray; diff --git a/packages/flutter/lib/src/cupertino/thumb_painter.dart b/packages/flutter/lib/src/cupertino/thumb_painter.dart index 3c7d696d067..319c6a00e96 100644 --- a/packages/flutter/lib/src/cupertino/thumb_painter.dart +++ b/packages/flutter/lib/src/cupertino/thumb_painter.dart @@ -47,7 +47,7 @@ class CupertinoThumbPainter { const CupertinoThumbPainter({ this.color = CupertinoColors.white, this.shadows = _kSliderBoxShadows, - }) : assert(shadows != null); + }); /// Creates an object that paints an iOS-style switch thumb. const CupertinoThumbPainter.switchThumb({