RenderIndexedStack - Mark invisible children as offstage in debugDescribeProperties (#96639)
This commit is contained in:
parent
3facdb8717
commit
36a8f0f2ae
@ -749,4 +749,20 @@ class RenderIndexedStack extends RenderStack {
|
|||||||
super.debugFillProperties(properties);
|
super.debugFillProperties(properties);
|
||||||
properties.add(IntProperty('index', index));
|
properties.add(IntProperty('index', index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<DiagnosticsNode> debugDescribeChildren() {
|
||||||
|
final List<DiagnosticsNode> children = <DiagnosticsNode>[];
|
||||||
|
int i = 0;
|
||||||
|
RenderObject? child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
children.add(child.toDiagnosticsNode(
|
||||||
|
name: 'child ${i + 1}',
|
||||||
|
style: i != index! ? DiagnosticsTreeStyle.offstage : null,
|
||||||
|
));
|
||||||
|
child = (child.parentData! as StackParentData).nextSibling;
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
return children;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
@ -118,6 +119,33 @@ void main() {
|
|||||||
expect(visitedChildren.first, child2);
|
expect(visitedChildren.first, child2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('debugDescribeChildren marks invisible children as offstage', () {
|
||||||
|
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: 2,
|
||||||
|
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.sparse);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// More tests in ../widgets/stack_test.dart
|
// More tests in ../widgets/stack_test.dart
|
||||||
|
Loading…
x
Reference in New Issue
Block a user