use FlutterError in MultiChildRenderObjectWidget (#37187)
This commit is contained in:
parent
a0b69f3070
commit
9357e70dfd
@ -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);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user