Skip to content

Commit 59767e5

Browse files
authored
Remove unnecessary null checks in flutter/material (#119022)
* dart fix --apply * manual fixes
1 parent 6548616 commit 59767e5

File tree

131 files changed

+262
-1293
lines changed

Some content is hidden

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

131 files changed

+262
-1293
lines changed

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ void showAboutDialog({
184184
RouteSettings? routeSettings,
185185
Offset? anchorPoint,
186186
}) {
187-
assert(context != null);
188-
assert(useRootNavigator != null);
189187
showDialog<void>(
190188
context: context,
191189
useRootNavigator: useRootNavigator,
@@ -230,8 +228,6 @@ void showLicensePage({
230228
String? applicationLegalese,
231229
bool useRootNavigator = false,
232230
}) {
233-
assert(context != null);
234-
assert(useRootNavigator != null);
235231
Navigator.of(context, rootNavigator: useRootNavigator).push(MaterialPageRoute<void>(
236232
builder: (BuildContext context) => LicensePage(
237233
applicationName: applicationName,
@@ -486,8 +482,7 @@ class _AboutProgram extends StatelessWidget {
486482
required this.version,
487483
this.icon,
488484
this.legalese,
489-
}) : assert(name != null),
490-
assert(version != null);
485+
});
491486

492487
final String name;
493488
final String version;
@@ -542,8 +537,7 @@ class _PackagesView extends StatefulWidget {
542537
required this.about,
543538
required this.isLateral,
544539
required this.selectedId,
545-
}) : assert(about != null),
546-
assert(isLateral != null);
540+
});
547541

548542
final Widget about;
549543
final bool isLateral;
@@ -1044,14 +1038,11 @@ class _MasterDetailFlow extends StatefulWidget {
10441038
const _MasterDetailFlow({
10451039
required this.detailPageBuilder,
10461040
required this.masterViewBuilder,
1047-
this.automaticallyImplyLeading = true,
1041+
this.automaticallyImplyLeading = true, // ignore: unused_element
10481042
this.detailPageFABlessGutterWidth,
1049-
this.displayMode = _LayoutMode.auto,
1043+
this.displayMode = _LayoutMode.auto, // ignore: unused_element
10501044
this.title,
1051-
}) : assert(masterViewBuilder != null),
1052-
assert(automaticallyImplyLeading != null),
1053-
assert(detailPageBuilder != null),
1054-
assert(displayMode != null);
1045+
});
10551046

10561047
/// Builder for the master view for lateral navigation.
10571048
///
@@ -1312,8 +1303,7 @@ class _MasterDetailScaffold extends StatefulWidget {
13121303
this.title,
13131304
required this.automaticallyImplyLeading,
13141305
this.detailPageFABlessGutterWidth,
1315-
}) : assert(detailPageBuilder != null),
1316-
assert(masterViewBuilder != null);
1306+
});
13171307

13181308
final _MasterViewBuilder masterViewBuilder;
13191309

@@ -1462,8 +1452,7 @@ class _DetailView extends StatelessWidget {
14621452
const _DetailView({
14631453
required _DetailPageBuilder builder,
14641454
Object? arguments,
1465-
}) : assert(builder != null),
1466-
_builder = builder,
1455+
}) : _builder = builder,
14671456
_arguments = arguments;
14681457

14691458
final _DetailPageBuilder _builder;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ class ActionChip extends StatelessWidget implements ChipAttributes, TappableChip
8686
this.shadowColor,
8787
this.surfaceTintColor,
8888
this.iconTheme,
89-
}) : assert(label != null),
90-
assert(clipBehavior != null),
91-
assert(autofocus != null),
92-
assert(pressElevation == null || pressElevation >= 0.0),
89+
}) : assert(pressElevation == null || pressElevation >= 0.0),
9390
assert(elevation == null || elevation >= 0.0);
9491

9592
@override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class AnimatedIcon extends StatelessWidget {
3939
this.size,
4040
this.semanticLabel,
4141
this.textDirection,
42-
}) : assert(progress != null),
43-
assert(icon != null);
42+
});
4443

4544
/// The animation progress for the animated icon.
4645
///

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,7 @@ class MaterialApp extends StatefulWidget {
242242
this.restorationScopeId,
243243
this.scrollBehavior,
244244
this.useInheritedMediaQuery = false,
245-
}) : assert(routes != null),
246-
assert(navigatorObservers != null),
247-
assert(title != null),
248-
assert(debugShowMaterialGrid != null),
249-
assert(showPerformanceOverlay != null),
250-
assert(checkerboardRasterCacheImages != null),
251-
assert(checkerboardOffscreenLayers != null),
252-
assert(showSemanticsDebugger != null),
253-
assert(debugShowCheckedModeBanner != null),
254-
routeInformationProvider = null,
245+
}) : routeInformationProvider = null,
255246
routeInformationParser = null,
256247
routerDelegate = null,
257248
backButtonDispatcher = null,
@@ -296,13 +287,6 @@ class MaterialApp extends StatefulWidget {
296287
this.scrollBehavior,
297288
this.useInheritedMediaQuery = false,
298289
}) : assert(routerDelegate != null || routerConfig != null),
299-
assert(title != null),
300-
assert(debugShowMaterialGrid != null),
301-
assert(showPerformanceOverlay != null),
302-
assert(checkerboardRasterCacheImages != null),
303-
assert(checkerboardOffscreenLayers != null),
304-
assert(showSemanticsDebugger != null),
305-
assert(debugShowCheckedModeBanner != null),
306290
navigatorObservers = null,
307291
navigatorKey = null,
308292
onGenerateRoute = null,

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
223223
this.titleTextStyle,
224224
this.systemOverlayStyle,
225225
this.forceMaterialTransparency = false,
226-
}) : assert(automaticallyImplyLeading != null),
227-
assert(elevation == null || elevation >= 0.0),
228-
assert(notificationPredicate != null),
229-
assert(primary != null),
230-
assert(toolbarOpacity != null),
231-
assert(bottomOpacity != null),
226+
}) : assert(elevation == null || elevation >= 0.0),
232227
preferredSize = _PreferredAppBarSize(toolbarHeight, bottom?.preferredSize.height);
233228

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

810805
bool _getEffectiveCenterTitle(ThemeData theme) {
811806
bool platformCenter() {
812-
assert(theme.platform != null);
813807
switch (theme.platform) {
814808
case TargetPlatform.android:
815809
case TargetPlatform.fuchsia:
@@ -1323,10 +1317,6 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
13231317
required this.systemOverlayStyle,
13241318
required this.forceMaterialTransparency,
13251319
}) : assert(primary || topPadding == 0.0),
1326-
assert(
1327-
!floating || (snapConfiguration == null && showOnScreenConfiguration == null) || vsync != null,
1328-
'vsync cannot be null when snapConfiguration or showOnScreenConfiguration is not null, and floating is true',
1329-
),
13301320
_bottomHeight = bottom?.preferredSize.height ?? 0.0;
13311321

13321322
final Widget? leading;
@@ -1627,15 +1617,7 @@ class SliverAppBar extends StatefulWidget {
16271617
this.titleTextStyle,
16281618
this.systemOverlayStyle,
16291619
this.forceMaterialTransparency = false,
1630-
}) : assert(automaticallyImplyLeading != null),
1631-
assert(forceElevated != null),
1632-
assert(primary != null),
1633-
assert(floating != null),
1634-
assert(pinned != null),
1635-
assert(snap != null),
1636-
assert(stretch != null),
1637-
assert(toolbarHeight != null),
1638-
assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'),
1620+
}) : assert(floating || !snap, 'The "snap" argument only makes sense for floating app bars.'),
16391621
assert(stretchTriggerOffset > 0.0),
16401622
assert(collapsedHeight == null || collapsedHeight >= toolbarHeight, 'The "collapsedHeight" argument has to be larger than or equal to [toolbarHeight].');
16411623

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

22462228
@override
22472229
_RenderAppBarTitleBox createRenderObject(BuildContext context) {
@@ -2332,7 +2314,6 @@ class _ScrollUnderFlexibleSpace extends StatelessWidget {
23322314
late final bool centerTitle;
23332315
{
23342316
bool platformCenter() {
2335-
assert(theme.platform != null);
23362317
switch (theme.platform) {
23372318
case TargetPlatform.android:
23382319
case TargetPlatform.fuchsia:

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ class AppBarTheme with Diagnosticable {
306306
///
307307
/// {@macro dart.ui.shadow.lerp}
308308
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
309-
assert(t != null);
310309
return AppBarTheme(
311310
brightness: t < 0.5 ? a?.brightness : b?.brightness,
312311
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class Autocomplete<T extends Object> extends StatelessWidget {
4343
this.optionsMaxHeight = 200.0,
4444
this.optionsViewBuilder,
4545
this.initialValue,
46-
}) : assert(displayStringForOption != null),
47-
assert(optionsBuilder != null);
46+
});
4847

4948
/// {@macro flutter.widgets.RawAutocomplete.displayStringForOption}
5049
final AutocompleteOptionToString<T> displayStringForOption;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class BadgeTheme extends InheritedTheme {
153153
super.key,
154154
required this.data,
155155
required super.child,
156-
}) : assert(data != null);
156+
});
157157

158158
/// Specifies the default color and size overrides for descendant [Badge] widgets.
159159
final BadgeThemeData data;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ class MaterialBanner extends StatefulWidget {
111111
this.overflowAlignment = OverflowBarAlignment.end,
112112
this.animation,
113113
this.onVisible,
114-
}) : assert(elevation == null || elevation >= 0.0),
115-
assert(content != null),
116-
assert(actions != null),
117-
assert(forceActionsBelow != null);
114+
}) : assert(elevation == null || elevation >= 0.0);
118115

119116
/// The content of the [MaterialBanner].
120117
///

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class MaterialBannerThemeData with Diagnosticable {
101101
///
102102
/// {@macro dart.ui.shadow.lerp}
103103
static MaterialBannerThemeData lerp(MaterialBannerThemeData? a, MaterialBannerThemeData? b, double t) {
104-
assert(t != null);
105104
return MaterialBannerThemeData(
106105
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
107106
surfaceTintColor: Color.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t),

0 commit comments

Comments
 (0)