@@ -2018,11 +2018,11 @@ class _ConstraintRenderBox extends RenderBox
2018
2018
}
2019
2019
2020
2020
/// There should be no loop constraints
2021
- static void _debugCheckLoopConstraints (
2022
- List < _ConstrainedNode > nodeList, bool selfSizeConfirmed ) {
2021
+ static void _debugCheckLoopConstraints (List < _ConstrainedNode > nodeList,
2022
+ bool selfSizeConfirmed, int parentDepth ) {
2023
2023
for (final element in nodeList) {
2024
2024
try {
2025
- element.getDepth (selfSizeConfirmed);
2025
+ element.getDepth (selfSizeConfirmed, parentDepth );
2026
2026
} on StackOverflowError catch (_) {
2027
2027
throw ConstraintLayoutException (
2028
2028
'There are some loop constraints, please check the code. For layout performance considerations, constraints are always one-way, and there should be no two child elements directly or indirectly restrain each other. Each constraint should describe exactly where the child elements are located. Use Guideline to break loop constraints.' );
@@ -2454,7 +2454,7 @@ class _ConstraintRenderBox extends RenderBox
2454
2454
if (_debugCheckConstraints) {
2455
2455
List <_ConstrainedNode > nodeList = nodesMap.values.toList ();
2456
2456
_debugCheckConstraintsIntegrity (nodeList);
2457
- _debugCheckLoopConstraints (nodeList, true );
2457
+ _debugCheckLoopConstraints (nodeList, true , 0 );
2458
2458
}
2459
2459
return true ;
2460
2460
}());
@@ -2463,28 +2463,34 @@ class _ConstraintRenderBox extends RenderBox
2463
2463
assert (() {
2464
2464
if (_debugCheckConstraints) {
2465
2465
List <_ConstrainedNode > nodeList = nodesMap.values.toList ();
2466
+ late _ConstrainedNode parentNode;
2466
2467
for (int i = 0 ; i < nodeList.length; i++ ) {
2467
2468
if (nodeList[i].isParent ()) {
2468
- nodeList.removeAt (i);
2469
+ parentNode = nodeList.removeAt (i);
2469
2470
break ;
2470
2471
}
2471
2472
}
2472
2473
_debugCheckConstraintsIntegrity (nodeList);
2473
- _debugCheckLoopConstraints (nodeList, false );
2474
+ _debugCheckLoopConstraints (nodeList, false , parentNode.depth );
2474
2475
}
2475
2476
return true ;
2476
2477
}());
2477
2478
}
2478
2479
2479
2480
/// Sort by the depth of constraint from shallow to deep, the lowest depth is 0, representing parent
2480
2481
_layoutOrderList = nodesMap.values.toList ();
2481
- _layoutOrderList.sort ((left, right) {
2482
- return left.getDepth (selfSizeConfirmed) -
2483
- right.getDepth (selfSizeConfirmed);
2484
- });
2485
2482
2486
- if (! selfSizeConfirmed) {
2487
- nodesMap.remove (parent);
2483
+ if (selfSizeConfirmed) {
2484
+ _layoutOrderList.sort ((left, right) {
2485
+ return left.getDepth (selfSizeConfirmed, 0 ) -
2486
+ right.getDepth (selfSizeConfirmed, 0 );
2487
+ });
2488
+ } else {
2489
+ _ConstrainedNode parentNode = nodesMap.remove (parent)! ;
2490
+ _layoutOrderList.sort ((left, right) {
2491
+ return left.getDepth (selfSizeConfirmed, parentNode.depth) -
2492
+ right.getDepth (selfSizeConfirmed, parentNode.depth);
2493
+ });
2488
2494
}
2489
2495
2490
2496
_paintingOrderList = nodesMap.values.toList ();
@@ -3348,7 +3354,7 @@ class _ConstraintRenderBox extends RenderBox
3348
3354
paragraphBuilder.pushStyle (ui.TextStyle (
3349
3355
color: Colors .black,
3350
3356
));
3351
- paragraphBuilder.addText ("depth ${element .getDepth (null )}" );
3357
+ paragraphBuilder.addText ("depth ${element .getDepth (null , - 1 )}" );
3352
3358
ui.Paragraph paragraph = paragraphBuilder.build ();
3353
3359
paragraph.layout (ui.ParagraphConstraints (
3354
3360
width: element.getMeasuredWidth (),
@@ -3666,8 +3672,8 @@ class _ConstrainedNode {
3666
3672
return baseline;
3667
3673
}
3668
3674
3669
- int getDepthFor (
3670
- _ConstrainedNode ? constrainedNode, bool ? parentSizeConfirmed ) {
3675
+ int getDepthFor (_ConstrainedNode ? constrainedNode, bool ? parentSizeConfirmed,
3676
+ int parentDepth ) {
3671
3677
if (constrainedNode == null ) {
3672
3678
return - 1 ;
3673
3679
}
@@ -3680,29 +3686,34 @@ class _ConstrainedNode {
3680
3686
}
3681
3687
}
3682
3688
}
3683
- return constrainedNode.getDepth (parentSizeConfirmed);
3689
+ return constrainedNode.getDepth (parentSizeConfirmed, parentDepth );
3684
3690
}
3685
3691
3686
- int getDepth (bool ? parentSizeConfirmed) {
3692
+ int getDepth (bool ? parentSizeConfirmed, int parentDepth ) {
3687
3693
if (depth < 0 ) {
3688
3694
if (isBarrier) {
3689
3695
List <int > list = [];
3690
3696
for (final id in referencedIds! ) {
3691
3697
list.add (parentData._constrainedNodeMap[id]!
3692
- .getDepth (parentSizeConfirmed));
3698
+ .getDepth (parentSizeConfirmed, parentDepth ));
3693
3699
}
3694
3700
list.sort ((left, right) => left - right);
3695
3701
depth = list.last + 1 ;
3696
3702
} else {
3697
3703
List <int > list = [
3698
- getDepthFor (leftConstraint, parentSizeConfirmed),
3699
- getDepthFor (topConstraint, parentSizeConfirmed),
3700
- getDepthFor (rightConstraint, parentSizeConfirmed),
3701
- getDepthFor (bottomConstraint, parentSizeConfirmed),
3702
- getDepthFor (baselineConstraint, parentSizeConfirmed),
3704
+ getDepthFor (leftConstraint, parentSizeConfirmed, parentDepth ),
3705
+ getDepthFor (topConstraint, parentSizeConfirmed, parentDepth ),
3706
+ getDepthFor (rightConstraint, parentSizeConfirmed, parentDepth ),
3707
+ getDepthFor (bottomConstraint, parentSizeConfirmed, parentDepth ),
3708
+ getDepthFor (baselineConstraint, parentSizeConfirmed, parentDepth ),
3703
3709
];
3704
3710
list.sort ((left, right) => left - right);
3705
3711
depth = list.last + 1 ;
3712
+ if (parentSizeConfirmed == false ) {
3713
+ if (width == matchConstraint || height == matchConstraint) {
3714
+ depth = max (depth, parentDepth + 1 );
3715
+ }
3716
+ }
3706
3717
}
3707
3718
}
3708
3719
return depth;
@@ -3778,7 +3789,7 @@ class _ConstrainedNode {
3778
3789
}
3779
3790
}
3780
3791
}
3781
- map['depth' ] = getDepth (null );
3792
+ map['depth' ] = getDepth (null , - 1 );
3782
3793
return map;
3783
3794
}
3784
3795
}
0 commit comments