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 {
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"
throw FlutterError(
"$runtimeType's children must not contain any null values, "
'but a null value was found at index $index'
);
}
return true;
......
......@@ -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() {
testWidgets('MultiChildRenderObjectElement control test', (WidgetTester tester) async {
......@@ -345,4 +352,17 @@ void main() {
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