Unverified Commit 9357e70d authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

use FlutterError in MultiChildRenderObjectWidget (#37187)

parent a0b69f30
...@@ -1688,8 +1688,9 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { ...@@ -1688,8 +1688,9 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
assert(() { assert(() {
final int index = children.indexOf(null); final int index = children.indexOf(null);
if (index >= 0) { if (index >= 0) {
throw AssertionError( throw FlutterError(
"The widget's children must not contain any null values, but a null value was found at index $index" "$runtimeType's children must not contain any null values, "
'but a null value was found at index $index'
); );
} }
return true; return true;
......
...@@ -31,6 +31,13 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) { ...@@ -31,6 +31,13 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
} }
} }
class MockMultiChildRenderObjectWidget extends MultiChildRenderObjectWidget {
MockMultiChildRenderObjectWidget({ Key key, List<Widget> children }) : super(key: key, children: children);
@override
RenderObject createRenderObject(BuildContext context) => null;
}
void main() { void main() {
testWidgets('MultiChildRenderObjectElement control test', (WidgetTester tester) async { testWidgets('MultiChildRenderObjectElement control test', (WidgetTester tester) async {
...@@ -345,4 +352,17 @@ void main() { ...@@ -345,4 +352,17 @@ void main() {
checkTree(tester, <BoxDecoration>[kBoxDecorationB, kBoxDecorationC]); checkTree(tester, <BoxDecoration>[kBoxDecorationB, kBoxDecorationC]);
}); });
// Regression test for https://github.com/flutter/flutter/issues/37136.
test('provides useful assertion message when one of the children is null', () {
bool assertionTriggered = false;
try {
MockMultiChildRenderObjectWidget(children: const <Widget>[null]);
} catch (e) {
expect(e.toString(), contains("MockMultiChildRenderObjectWidget's children must not contain any null values,"));
assertionTriggered = true;
}
expect(assertionTriggered, isTrue);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment