diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 69b67f7407..b9da094301 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -790,7 +790,7 @@ class RenderIndexedStack extends RenderStack { while (child != null) { children.add(child.toDiagnosticsNode( name: 'child ${i + 1}', - style: i != index! ? DiagnosticsTreeStyle.offstage : null, + style: i != index ? DiagnosticsTreeStyle.offstage : null, )); child = (child.parentData! as StackParentData).nextSibling; i += 1; diff --git a/packages/flutter/test/rendering/stack_test.dart b/packages/flutter/test/rendering/stack_test.dart index ca824ded1f..099d51c53a 100644 --- a/packages/flutter/test/rendering/stack_test.dart +++ b/packages/flutter/test/rendering/stack_test.dart @@ -145,6 +145,34 @@ void main() { expect(diagnosticNodes[2].name, 'child 3'); expect(diagnosticNodes[2].style, DiagnosticsTreeStyle.sparse); }); + + test('debugDescribeChildren handles a null index', () { + final RenderBox child1 = RenderConstrainedBox( + additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), + ); + final RenderBox child2 = RenderConstrainedBox( + additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), + ); + final RenderBox child3 = RenderConstrainedBox( + additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), + ); + + final RenderBox stack = RenderIndexedStack( + index: null, + children: [child1, child2, child3], + ); + + final List diagnosticNodes = stack.debugDescribeChildren(); + + expect(diagnosticNodes[0].name, 'child 1'); + expect(diagnosticNodes[0].style, DiagnosticsTreeStyle.offstage); + + expect(diagnosticNodes[1].name, 'child 2'); + expect(diagnosticNodes[1].style, DiagnosticsTreeStyle.offstage); + + expect(diagnosticNodes[2].name, 'child 3'); + expect(diagnosticNodes[2].style, DiagnosticsTreeStyle.offstage); + }); }); test('Stack in Flex can layout with no children', () {