Add a more meaningful message to the assertion on children property of MultiChildRenderObjectWidget and SliverChildListDelegate. (#32487)

This commit is contained in:
Efthymis Sarmpanis
2019-05-14 22:41:07 +03:00
committed by Kate Lovett
parent d9f6cada1c
commit 7498ad00b5
2 changed files with 13 additions and 2 deletions

View File

@@ -1663,7 +1663,15 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
/// objects.
MultiChildRenderObjectWidget({ Key key, this.children = const <Widget>[] })
: assert(children != null),
assert(!children.any((Widget child) => child == null)), // https://github.com/dart-lang/sdk/issues/29276
assert(() {
final int index = children.indexOf(null);
if (index >= 0) {
throw AssertionError(
"The widget's children must not contain any null values, but a null value was found at index $index"
);
}
return true;
}()), // https://github.com/dart-lang/sdk/issues/29276
super(key: key);
/// The widgets below this widget in the tree.

View File

@@ -670,7 +670,10 @@ class SliverChildListDelegate extends SliverChildDelegate {
return null;
Widget child = children[index];
final Key key = child.key != null? _SaltedValueKey(child.key) : null;
assert(child != null);
assert(
child != null,
"The sliver's children must not contain null values, but a null value was found at index $index"
);
if (addRepaintBoundaries)
child = RepaintBoundary(child: child);
if (addSemanticIndexes) {