Skip to content

Commit

Permalink
fix null safe check in RenderIndexedStack (#107581)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino authored Jul 13, 2022
1 parent d949ca4 commit b26346f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions packages/flutter/test/rendering/stack_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <RenderBox>[child1, child2, child3],
);

final List<DiagnosticsNode> 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', () {
Expand Down

0 comments on commit b26346f

Please sign in to comment.