Skip to content

Commit b26346f

Browse files
fix null safe check in RenderIndexedStack (#107581)
1 parent d949ca4 commit b26346f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/flutter/lib/src/rendering/stack.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ class RenderIndexedStack extends RenderStack {
790790
while (child != null) {
791791
children.add(child.toDiagnosticsNode(
792792
name: 'child ${i + 1}',
793-
style: i != index! ? DiagnosticsTreeStyle.offstage : null,
793+
style: i != index ? DiagnosticsTreeStyle.offstage : null,
794794
));
795795
child = (child.parentData! as StackParentData).nextSibling;
796796
i += 1;

packages/flutter/test/rendering/stack_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@ void main() {
145145
expect(diagnosticNodes[2].name, 'child 3');
146146
expect(diagnosticNodes[2].style, DiagnosticsTreeStyle.sparse);
147147
});
148+
149+
test('debugDescribeChildren handles a null index', () {
150+
final RenderBox child1 = RenderConstrainedBox(
151+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
152+
);
153+
final RenderBox child2 = RenderConstrainedBox(
154+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
155+
);
156+
final RenderBox child3 = RenderConstrainedBox(
157+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
158+
);
159+
160+
final RenderBox stack = RenderIndexedStack(
161+
index: null,
162+
children: <RenderBox>[child1, child2, child3],
163+
);
164+
165+
final List<DiagnosticsNode> diagnosticNodes = stack.debugDescribeChildren();
166+
167+
expect(diagnosticNodes[0].name, 'child 1');
168+
expect(diagnosticNodes[0].style, DiagnosticsTreeStyle.offstage);
169+
170+
expect(diagnosticNodes[1].name, 'child 2');
171+
expect(diagnosticNodes[1].style, DiagnosticsTreeStyle.offstage);
172+
173+
expect(diagnosticNodes[2].name, 'child 3');
174+
expect(diagnosticNodes[2].style, DiagnosticsTreeStyle.offstage);
175+
});
148176
});
149177

150178
test('Stack in Flex can layout with no children', () {

0 commit comments

Comments
 (0)