From d227788a5398f6e149906a7ec2416c3282cebf8f Mon Sep 17 00:00:00 2001 From: Konstantin Scheglov Date: Tue, 29 Sep 2020 11:47:21 -0700 Subject: [PATCH] Move assert(s) that reference 'this' to the constructor bodies. (#66914) --- packages/flutter/lib/src/cupertino/route.dart | 10 ++++---- packages/flutter/lib/src/material/page.dart | 10 ++++---- .../flutter/lib/src/widgets/framework.dart | 23 ++++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 003b2e043c..ee4ec55275 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -349,8 +349,9 @@ class CupertinoPageRoute extends PageRoute with CupertinoRouteTransitionMi }) : assert(builder != null), assert(maintainState != null), assert(fullscreenDialog != null), - assert(opaque), - super(settings: settings, fullscreenDialog: fullscreenDialog); + super(settings: settings, fullscreenDialog: fullscreenDialog) { + assert(opaque); + } /// Builds the primary contents of the route. final WidgetBuilder builder; @@ -376,8 +377,9 @@ class _PageBasedCupertinoPageRoute extends PageRoute with CupertinoRouteTr _PageBasedCupertinoPageRoute({ required CupertinoPage page, }) : assert(page != null), - assert(opaque), - super(settings: page); + super(settings: page) { + assert(opaque); + } CupertinoPage get _page => settings as CupertinoPage; diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index 278990bd8e..b27b675cfd 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -45,8 +45,9 @@ class MaterialPageRoute extends PageRoute with MaterialRouteTransitionMixi }) : assert(builder != null), assert(maintainState != null), assert(fullscreenDialog != null), - assert(opaque), - super(settings: settings, fullscreenDialog: fullscreenDialog); + super(settings: settings, fullscreenDialog: fullscreenDialog) { + assert(opaque); + } /// Builds the primary contents of the route. final WidgetBuilder builder; @@ -186,8 +187,9 @@ class _PageBasedMaterialPageRoute extends PageRoute with MaterialRouteTran _PageBasedMaterialPageRoute({ @required MaterialPage page, }) : assert(page != null), - assert(opaque), - super(settings: page); + super(settings: page) { + assert(opaque); + } MaterialPage get _page => settings as MaterialPage; diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 00ca2eb92a..eba932b573 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -1918,19 +1918,20 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { /// objects. MultiChildRenderObjectWidget({ Key? key, this.children = const [] }) : assert(children != null), - assert(() { - for (int index = 0; index < children.length; index++) { - // TODO(a14n): remove this check to have a lot more const widget - if (children[index] == null) { // ignore: dead_code - throw FlutterError( + super(key: key) { + assert(() { + for (int index = 0; index < children.length; index++) { + // TODO(a14n): remove this check to have a lot more const widget + if (children[index] == null) { // ignore: dead_code + throw FlutterError( "$runtimeType's children must not contain any null values, " - 'but a null value was found at index $index' - ); - } + 'but a null value was found at index $index' + ); } - return true; - }()), // https://github.com/dart-lang/sdk/issues/29276 - super(key: key); + } + return true; + }()); // https://github.com/dart-lang/sdk/issues/29276 + } /// The widgets below this widget in the tree. ///