Skip to content

Commit f1165c8

Browse files
committed
print child depth
1 parent 4e6436f commit f1165c8

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lib/src/constraint_layout.dart

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
2222
final bool releasePrintLayoutTime;
2323
final String? debugName;
2424
final bool debugShowZIndex;
25+
final bool debugShowChildDepth;
2526

2627
ConstraintLayout({
2728
Key? key,
@@ -35,6 +36,7 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
3536
this.releasePrintLayoutTime = false,
3637
this.debugName,
3738
this.debugShowZIndex = false,
39+
this.debugShowChildDepth = false,
3840
}) : super(
3941
key: key,
4042
children: children,
@@ -52,7 +54,8 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
5254
.._debugCheckConstraints = debugCheckConstraints
5355
.._releasePrintLayoutTime = releasePrintLayoutTime
5456
.._debugName = debugName
55-
.._debugShowZIndex = debugShowZIndex;
57+
.._debugShowZIndex = debugShowZIndex
58+
.._debugShowChildDepth = debugShowChildDepth;
5659
}
5760

5861
@override
@@ -70,7 +73,8 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
7073
..debugCheckConstraints = debugCheckConstraints
7174
..releasePrintLayoutTime = releasePrintLayoutTime
7275
..debugName = debugName
73-
..debugShowZIndex = debugShowZIndex;
76+
..debugShowZIndex = debugShowZIndex
77+
..debugShowChildDepth = debugShowChildDepth;
7478
}
7579
}
7680

@@ -1533,6 +1537,7 @@ class _ConstraintRenderBox extends RenderBox
15331537
late bool _releasePrintLayoutTime;
15341538
String? _debugName;
15351539
late bool _debugShowZIndex;
1540+
late bool _debugShowChildDepth;
15361541

15371542
bool _needsRecalculateConstraints = true;
15381543
bool _needsReorderChildren = true;
@@ -1676,6 +1681,13 @@ class _ConstraintRenderBox extends RenderBox
16761681
}
16771682
}
16781683

1684+
set debugShowChildDepth(bool value) {
1685+
if (_debugShowChildDepth != value) {
1686+
_debugShowChildDepth = value;
1687+
markNeedsPaint();
1688+
}
1689+
}
1690+
16791691
set needsReorderChildren(bool value) {
16801692
if (_needsReorderChildren != value) {
16811693
_needsReorderChildren = value;
@@ -2764,6 +2776,32 @@ class _ConstraintRenderBox extends RenderBox
27642776
}
27652777
return true;
27662778
}());
2779+
2780+
assert(() {
2781+
if (_debugShowChildDepth) {
2782+
ui.ParagraphBuilder paragraphBuilder =
2783+
ui.ParagraphBuilder(ui.ParagraphStyle(
2784+
textAlign: TextAlign.center,
2785+
fontSize: 10,
2786+
));
2787+
paragraphBuilder.pushStyle(ui.TextStyle(
2788+
color: Colors.black,
2789+
));
2790+
paragraphBuilder.addText("depth ${element.getDepth()}");
2791+
ui.Paragraph paragraph = paragraphBuilder.build();
2792+
paragraph.layout(ui.ParagraphConstraints(
2793+
width: element.getMeasuredWidth(size),
2794+
));
2795+
context.canvas.drawParagraph(
2796+
paragraph,
2797+
element.offset +
2798+
offset +
2799+
paintShift +
2800+
Offset(
2801+
0, element.getMeasuredHeight(size) - paragraph.height));
2802+
}
2803+
return true;
2804+
}());
27672805
}
27682806

27692807
assert(() {

0 commit comments

Comments
 (0)