Skip to content

Commit

Permalink
Remove unnecessary null checks in flutter/material (#119022)
Browse files Browse the repository at this point in the history
* dart fix --apply

* manual fixes
  • Loading branch information
goderbauer authored Jan 24, 2023
1 parent 6548616 commit 59767e5
Show file tree
Hide file tree
Showing 131 changed files with 262 additions and 1,293 deletions.
25 changes: 7 additions & 18 deletions packages/flutter/lib/src/material/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ void showAboutDialog({
RouteSettings? routeSettings,
Offset? anchorPoint,
}) {
assert(context != null);
assert(useRootNavigator != null);
showDialog<void>(
context: context,
useRootNavigator: useRootNavigator,
Expand Down Expand Up @@ -230,8 +228,6 @@ void showLicensePage({
String? applicationLegalese,
bool useRootNavigator = false,
}) {
assert(context != null);
assert(useRootNavigator != null);
Navigator.of(context, rootNavigator: useRootNavigator).push(MaterialPageRoute<void>(
builder: (BuildContext context) => LicensePage(
applicationName: applicationName,
Expand Down Expand Up @@ -486,8 +482,7 @@ class _AboutProgram extends StatelessWidget {
required this.version,
this.icon,
this.legalese,
}) : assert(name != null),
assert(version != null);
});

final String name;
final String version;
Expand Down Expand Up @@ -542,8 +537,7 @@ class _PackagesView extends StatefulWidget {
required this.about,
required this.isLateral,
required this.selectedId,
}) : assert(about != null),
assert(isLateral != null);
});

final Widget about;
final bool isLateral;
Expand Down Expand Up @@ -1044,14 +1038,11 @@ class _MasterDetailFlow extends StatefulWidget {
const _MasterDetailFlow({
required this.detailPageBuilder,
required this.masterViewBuilder,
this.automaticallyImplyLeading = true,
this.automaticallyImplyLeading = true, // ignore: unused_element
this.detailPageFABlessGutterWidth,
this.displayMode = _LayoutMode.auto,
this.displayMode = _LayoutMode.auto, // ignore: unused_element
this.title,
}) : assert(masterViewBuilder != null),
assert(automaticallyImplyLeading != null),
assert(detailPageBuilder != null),
assert(displayMode != null);
});

/// Builder for the master view for lateral navigation.
///
Expand Down Expand Up @@ -1312,8 +1303,7 @@ class _MasterDetailScaffold extends StatefulWidget {
this.title,
required this.automaticallyImplyLeading,
this.detailPageFABlessGutterWidth,
}) : assert(detailPageBuilder != null),
assert(masterViewBuilder != null);
});

final _MasterViewBuilder masterViewBuilder;

Expand Down Expand Up @@ -1462,8 +1452,7 @@ class _DetailView extends StatelessWidget {
const _DetailView({
required _DetailPageBuilder builder,
Object? arguments,
}) : assert(builder != null),
_builder = builder,
}) : _builder = builder,
_arguments = arguments;

final _DetailPageBuilder _builder;
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter/lib/src/material/action_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
this.shadowColor,
this.surfaceTintColor,
this.iconTheme,
}) : assert(label != null),
assert(clipBehavior != null),
assert(autofocus != null),
assert(pressElevation == null || pressElevation >= 0.0),
}) : assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class AnimatedIcon extends StatelessWidget {
this.size,
this.semanticLabel,
this.textDirection,
}) : assert(progress != null),
assert(icon != null);
});

/// The animation progress for the animated icon.
///
Expand Down
18 changes: 1 addition & 17 deletions packages/flutter/lib/src/material/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,7 @@ class MaterialApp extends StatefulWidget {
this.restorationScopeId,
this.scrollBehavior,
this.useInheritedMediaQuery = false,
}) : assert(routes != null),
assert(navigatorObservers != null),
assert(title != null),
assert(debugShowMaterialGrid != 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 @@ -296,13 +287,6 @@ class MaterialApp extends StatefulWidget {
this.scrollBehavior,
this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null),
assert(title != null),
assert(debugShowMaterialGrid != null),
assert(showPerformanceOverlay != null),
assert(checkerboardRasterCacheImages != null),
assert(checkerboardOffscreenLayers != null),
assert(showSemanticsDebugger != null),
assert(debugShowCheckedModeBanner != null),
navigatorObservers = null,
navigatorKey = null,
onGenerateRoute = null,
Expand Down
25 changes: 3 additions & 22 deletions packages/flutter/lib/src/material/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this.titleTextStyle,
this.systemOverlayStyle,
this.forceMaterialTransparency = false,
}) : assert(automaticallyImplyLeading != null),
assert(elevation == null || elevation >= 0.0),
assert(notificationPredicate != null),
assert(primary != null),
assert(toolbarOpacity != null),
assert(bottomOpacity != null),
}) : assert(elevation == null || elevation >= 0.0),
preferredSize = _PreferredAppBarSize(toolbarHeight, bottom?.preferredSize.height);

/// Used by [Scaffold] to compute its [AppBar]'s overall height. The returned value is
Expand Down Expand Up @@ -809,7 +804,6 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {

bool _getEffectiveCenterTitle(ThemeData theme) {
bool platformCenter() {
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
Expand Down Expand Up @@ -1323,10 +1317,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
required this.systemOverlayStyle,
required this.forceMaterialTransparency,
}) : assert(primary || topPadding == 0.0),
assert(
!floating || (snapConfiguration == null && showOnScreenConfiguration == null) || vsync != null,
'vsync cannot be null when snapConfiguration or showOnScreenConfiguration is not null, and floating is true',
),
_bottomHeight = bottom?.preferredSize.height ?? 0.0;

final Widget? leading;
Expand Down Expand Up @@ -1627,15 +1617,7 @@ class SliverAppBar extends StatefulWidget {
this.titleTextStyle,
this.systemOverlayStyle,
this.forceMaterialTransparency = false,
}) : assert(automaticallyImplyLeading != null),
assert(forceElevated != null),
assert(primary != null),
assert(floating != null),
assert(pinned != null),
assert(snap != null),
assert(stretch != null),
assert(toolbarHeight != null),
assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'),
}) : assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'),
assert(stretchTriggerOffset > 0.0),
assert(collapsedHeight == null || collapsedHeight >= toolbarHeight, 'The "collapsedHeight" argument has to be larger than or equal to [toolbarHeight].');

Expand Down Expand Up @@ -2241,7 +2223,7 @@ class _SliverAppBarState extends State<SliverAppBar> with TickerProviderStateMix
// center it within its (NavigationToolbar) parent, and allow the
// parent to constrain the title's actual height.
class _AppBarTitleBox extends SingleChildRenderObjectWidget {
const _AppBarTitleBox({ required Widget super.child }) : assert(child != null);
const _AppBarTitleBox({ required Widget super.child });

@override
_RenderAppBarTitleBox createRenderObject(BuildContext context) {
Expand Down Expand Up @@ -2332,7 +2314,6 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
late final bool centerTitle;
{
bool platformCenter() {
assert(theme.platform != null);
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
Expand Down
1 change: 0 additions & 1 deletion packages/flutter/lib/src/material/app_bar_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ class AppBarTheme with Diagnosticable {
///
/// {@macro dart.ui.shadow.lerp}
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
assert(t != null);
return AppBarTheme(
brightness: t < 0.5 ? a?.brightness : b?.brightness,
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter/lib/src/material/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Autocomplete<T extends Object> extends StatelessWidget {
this.optionsMaxHeight = 200.0,
this.optionsViewBuilder,
this.initialValue,
}) : assert(displayStringForOption != null),
assert(optionsBuilder != null);
});

/// {@macro flutter.widgets.RawAutocomplete.displayStringForOption}
final AutocompleteOptionToString<T> displayStringForOption;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/badge_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class BadgeTheme extends InheritedTheme {
super.key,
required this.data,
required super.child,
}) : assert(data != null);
});

/// Specifies the default color and size overrides for descendant [Badge] widgets.
final BadgeThemeData data;
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter/lib/src/material/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ class MaterialBanner extends StatefulWidget {
this.overflowAlignment = OverflowBarAlignment.end,
this.animation,
this.onVisible,
}) : assert(elevation == null || elevation >= 0.0),
assert(content != null),
assert(actions != null),
assert(forceActionsBelow != null);
}) : assert(elevation == null || elevation >= 0.0);

/// The content of the [MaterialBanner].
///
Expand Down
1 change: 0 additions & 1 deletion packages/flutter/lib/src/material/banner_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class MaterialBannerThemeData with Diagnosticable {
///
/// {@macro dart.ui.shadow.lerp}
static MaterialBannerThemeData lerp(MaterialBannerThemeData? a, MaterialBannerThemeData? b, double t) {
assert(t != null);
return MaterialBannerThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t),
Expand Down
13 changes: 3 additions & 10 deletions packages/flutter/lib/src/material/bottom_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class BottomAppBar extends StatefulWidget {
this.padding,
this.surfaceTintColor,
this.height,
}) : assert(elevation == null || elevation >= 0.0),
assert(notchMargin != null),
assert(clipBehavior != null);
}) : assert(elevation == null || elevation >= 0.0);

/// The widget below this widget in the tree.
///
Expand Down Expand Up @@ -198,9 +196,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
elevation: elevation,
color: isMaterial3 ? effectiveColor : null,
surfaceTintColor: surfaceTintColor,
child: child == null
? null
: SafeArea(child: child),
child: SafeArea(child: child),
),
),
);
Expand All @@ -213,10 +209,7 @@ class _BottomAppBarClipper extends CustomClipper<Path> {
required this.shape,
required this.materialKey,
required this.notchMargin,
}) : assert(geometry != null),
assert(shape != null),
assert(notchMargin != null),
super(reclip: geometry);
}) : super(reclip: geometry);

final ValueListenable<ScaffoldGeometry> geometry;
final NotchedShape shape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class BottomAppBarTheme with Diagnosticable {
///
/// {@macro dart.ui.shadow.lerp}
static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) {
assert(t != null);
return BottomAppBarTheme(
color: Color.lerp(a?.color, b?.color, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t),
Expand Down
36 changes: 9 additions & 27 deletions packages/flutter/lib/src/material/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,20 @@ class BottomNavigationBar extends StatefulWidget {
this.enableFeedback,
this.landscapeLayout,
this.useLegacyColorScheme = true,
}) : assert(items != null),
assert(items.length >= 2),
}) : assert(items.length >= 2),
assert(
items.every((BottomNavigationBarItem item) => item.label != null),
'Every item must have a non-null label',
),
assert(0 <= currentIndex && currentIndex < items.length),
assert(elevation == null || elevation >= 0.0),
assert(iconSize != null && iconSize >= 0.0),
assert(iconSize >= 0.0),
assert(
selectedItemColor == null || fixedColor == null,
'Either selectedItemColor or fixedColor can be specified, but not both',
),
assert(selectedFontSize != null && selectedFontSize >= 0.0),
assert(unselectedFontSize != null && unselectedFontSize >= 0.0),
assert(selectedFontSize >= 0.0),
assert(unselectedFontSize >= 0.0),
selectedItemColor = selectedItemColor ?? fixedColor;

/// Defines the appearance of the button items that are arrayed within the
Expand Down Expand Up @@ -421,13 +420,7 @@ class _BottomNavigationTile extends StatelessWidget {
required this.mouseCursor,
required this.enableFeedback,
required this.layout,
}) : assert(type != null),
assert(item != null),
assert(animation != null),
assert(selected != null),
assert(selectedLabelStyle != null),
assert(unselectedLabelStyle != null),
assert(mouseCursor != null);
});

final BottomNavigationBarType type;
final BottomNavigationBarItem item;
Expand Down Expand Up @@ -633,8 +626,7 @@ class _TileIcon extends StatelessWidget {
required this.item,
required this.selectedIconTheme,
required this.unselectedIconTheme,
}) : assert(selected != null),
assert(item != null);
});

final ColorTween colorTween;
final Animation<double> animation;
Expand Down Expand Up @@ -677,13 +669,7 @@ class _Label extends StatelessWidget {
required this.unselectedLabelStyle,
required this.showSelectedLabels,
required this.showUnselectedLabels,
}) : assert(colorTween != null),
assert(animation != null),
assert(item != null),
assert(selectedLabelStyle != null),
assert(unselectedLabelStyle != null),
assert(showSelectedLabels != null),
assert(showUnselectedLabels != null);
});

final ColorTween colorTween;
final Animation<double> animation;
Expand Down Expand Up @@ -934,7 +920,6 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr

List<Widget> _createTiles(BottomNavigationBarLandscapeLayout layout) {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
assert(localizations != null);

final ThemeData themeData = Theme.of(context);
final BottomNavigationBarThemeData bottomTheme = BottomNavigationBarTheme.of(context);
Expand Down Expand Up @@ -1205,9 +1190,7 @@ class _Circle {
required this.index,
required this.color,
required TickerProvider vsync,
}) : assert(state != null),
assert(index != null),
assert(color != null) {
}) {
controller = AnimationController(
duration: kThemeAnimationDuration,
vsync: vsync,
Expand Down Expand Up @@ -1250,8 +1233,7 @@ class _RadialPainter extends CustomPainter {
_RadialPainter({
required this.circles,
required this.textDirection,
}) : assert(circles != null),
assert(textDirection != null);
});

final List<_Circle> circles;
final TextDirection textDirection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class BottomNavigationBarThemeData with Diagnosticable {
///
/// {@macro dart.ui.shadow.lerp}
static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData? a, BottomNavigationBarThemeData? b, double t) {
assert(t != null);
return BottomNavigationBarThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
elevation: lerpDouble(a?.elevation, b?.elevation, t),
Expand Down Expand Up @@ -280,7 +279,7 @@ class BottomNavigationBarTheme extends InheritedWidget {
super.key,
required this.data,
required super.child,
}) : assert(data != null);
});

/// The properties used for all descendant [BottomNavigationBar] widgets.
final BottomNavigationBarThemeData data;
Expand Down
Loading

0 comments on commit 59767e5

Please sign in to comment.