Skip to content

Commit 36a8f0f

Browse files
authored
RenderIndexedStack - Mark invisible children as offstage in debugDescribeProperties (#96639)
1 parent 3facdb8 commit 36a8f0f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,20 @@ class RenderIndexedStack extends RenderStack {
749749
super.debugFillProperties(properties);
750750
properties.add(IntProperty('index', index));
751751
}
752+
753+
@override
754+
List<DiagnosticsNode> debugDescribeChildren() {
755+
final List<DiagnosticsNode> children = <DiagnosticsNode>[];
756+
int i = 0;
757+
RenderObject? child = firstChild;
758+
while (child != null) {
759+
children.add(child.toDiagnosticsNode(
760+
name: 'child ${i + 1}',
761+
style: i != index! ? DiagnosticsTreeStyle.offstage : null,
762+
));
763+
child = (child.parentData! as StackParentData).nextSibling;
764+
i += 1;
765+
}
766+
return children;
767+
}
752768
}

packages/flutter/test/rendering/stack_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/rendering.dart';
67
import 'package:flutter_test/flutter_test.dart';
78

@@ -118,6 +119,33 @@ void main() {
118119
expect(visitedChildren.first, child2);
119120
});
120121

122+
test('debugDescribeChildren marks invisible children as offstage', () {
123+
final RenderBox child1 = RenderConstrainedBox(
124+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
125+
);
126+
final RenderBox child2 = RenderConstrainedBox(
127+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
128+
);
129+
final RenderBox child3 = RenderConstrainedBox(
130+
additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)),
131+
);
132+
133+
final RenderBox stack = RenderIndexedStack(
134+
index: 2,
135+
children: <RenderBox>[child1, child2, child3],
136+
);
137+
138+
final List<DiagnosticsNode> diagnosticNodes = stack.debugDescribeChildren();
139+
140+
expect(diagnosticNodes[0].name, 'child 1');
141+
expect(diagnosticNodes[0].style, DiagnosticsTreeStyle.offstage);
142+
143+
expect(diagnosticNodes[1].name, 'child 2');
144+
expect(diagnosticNodes[1].style, DiagnosticsTreeStyle.offstage);
145+
146+
expect(diagnosticNodes[2].name, 'child 3');
147+
expect(diagnosticNodes[2].style, DiagnosticsTreeStyle.sparse);
148+
});
121149
});
122150

123151
// More tests in ../widgets/stack_test.dart

0 commit comments

Comments
 (0)