@@ -22,7 +22,7 @@ import 'package:flutter/rendering.dart';
22
22
23
23
class ConstraintLayout extends MultiChildRenderObjectWidget {
24
24
/// Constraints can be separated from widgets
25
- final List <Constraint >? childConstraints;
25
+ final List <Constraint > childConstraints;
26
26
27
27
final bool debugShowGuideline;
28
28
final bool debugShowClickArea;
@@ -35,7 +35,7 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
35
35
36
36
ConstraintLayout ({
37
37
Key ? key,
38
- this .childConstraints,
38
+ this .childConstraints = const [] ,
39
39
required List <Widget > children,
40
40
this .debugShowGuideline = false ,
41
41
this .debugShowClickArea = false ,
@@ -113,7 +113,8 @@ List<Widget> horizontalChain({
113
113
// packed
114
114
}
115
115
116
- ConstraintId guidelineId = ConstraintId ();
116
+ ConstraintId guidelineId = ConstraintId (
117
+ 'internal_horizontal_chain_guideline_$i @${chainList [0 ].constraint .hashCode }' );
117
118
Guideline guideline = Guideline (
118
119
id: guidelineId,
119
120
horizontal: false ,
@@ -276,7 +277,7 @@ bool _debugEnsureNegativePercent(String name, double? percent) {
276
277
return true ;
277
278
}
278
279
279
- ConstraintId parent = ConstraintId ();
280
+ ConstraintId parent = ConstraintId ('parent' );
280
281
const double matchConstraint = - 3.1415926 ;
281
282
const double matchParent = - 2.7182818 ;
282
283
const double wrapContent = - 0.6180339 ;
@@ -309,9 +310,9 @@ enum PercentageAnchor {
309
310
}
310
311
311
312
class ConstraintId {
312
- String ? name ;
313
+ String id ;
313
314
314
- ConstraintId ({ this .name} ) {
315
+ ConstraintId (this .id ) {
315
316
left.id = this ;
316
317
top.id = this ;
317
318
right.id = this ;
@@ -340,24 +341,17 @@ class ConstraintId {
340
341
if (other.runtimeType != runtimeType) {
341
342
return false ;
342
343
}
343
- if ((other).name == null && name == null ) {
344
- return false ;
345
- }
346
- return (other).name == name;
344
+ return (other).id == id;
347
345
}
348
346
349
347
@override
350
348
int get hashCode {
351
- if (name == null ) {
352
- return super .hashCode;
353
- } else {
354
- return name.hashCode;
355
- }
349
+ return id.hashCode;
356
350
}
357
351
358
352
@override
359
353
String toString () {
360
- return 'ConstraintId{name: $name }' ;
354
+ return 'ConstraintId{name: $id }' ;
361
355
}
362
356
}
363
357
@@ -992,12 +986,10 @@ class UnConstrained extends ParentDataWidget<_ConstraintBoxData> {
992
986
@override
993
987
void applyParentData (RenderObject renderObject) {
994
988
assert (renderObject.parent is _ConstraintRenderBox );
995
- List <Constraint >? childConstraints =
989
+ List <Constraint > childConstraints =
996
990
(renderObject.parent as _ConstraintRenderBox )._childConstraints;
997
- assert (childConstraints != null ,
998
- 'Can not find Constraint for child with id $id .' );
999
991
Iterable <Constraint > constraintIterable =
1000
- childConstraints! .where ((element) => element.id == id);
992
+ childConstraints.where ((element) => element.id == id);
1001
993
assert (constraintIterable.isNotEmpty,
1002
994
'Can not find Constraint for child with id $id .' );
1003
995
assert (constraintIterable.length == 1 , 'Duplicate id in childConstraints.' );
@@ -1016,7 +1008,7 @@ class _ConstraintRenderBox extends RenderBox
1016
1008
with
1017
1009
ContainerRenderObjectMixin <RenderBox , _ConstraintBoxData >,
1018
1010
RenderBoxContainerDefaultsMixin <RenderBox , _ConstraintBoxData > {
1019
- List <Constraint >? _childConstraints;
1011
+ late List <Constraint > _childConstraints;
1020
1012
late bool _debugShowGuideline;
1021
1013
late bool _debugShowClickArea;
1022
1014
late bool _debugPrintConstraints;
@@ -1031,8 +1023,19 @@ class _ConstraintRenderBox extends RenderBox
1031
1023
final Map <ConstraintId , _ConstrainedNode > _tempConstrainedNodes = HashMap ();
1032
1024
late List <_ConstrainedNode > _paintingOrderList;
1033
1025
1034
- set childConstraints (List <Constraint >? value) {
1035
- if (_childConstraints != value) {
1026
+ set childConstraints (List <Constraint > value) {
1027
+ bool isSameList = true ;
1028
+ if (_childConstraints.length != value.length) {
1029
+ isSameList = false ;
1030
+ } else {
1031
+ for (int i = 0 ; i < _childConstraints.length; i++ ) {
1032
+ if (_childConstraints[i] != value[i]) {
1033
+ isSameList = false ;
1034
+ break ;
1035
+ }
1036
+ }
1037
+ }
1038
+ if (! isSameList) {
1036
1039
_childConstraints = value;
1037
1040
markNeedsLayout ();
1038
1041
}
@@ -1255,8 +1258,7 @@ class _ConstraintRenderBox extends RenderBox
1255
1258
child,
1256
1259
childParentData.id ??
1257
1260
ConstraintId (
1258
- name:
1259
- 'child[$childIndex ]@${child .runtimeType }@${child .hashCode }' ));
1261
+ 'child[$childIndex ]@${child .runtimeType }@${child .hashCode }' ));
1260
1262
currentNode.parentData = childParentData;
1261
1263
currentNode.index = childIndex;
1262
1264
@@ -2583,7 +2585,18 @@ class _BarrierRenderBox extends _InternalBox {
2583
2585
}
2584
2586
2585
2587
set referencedIds (List <ConstraintId > value) {
2586
- if (_referencedIds != value) {
2588
+ bool isSameList = true ;
2589
+ if (_referencedIds.length != value.length) {
2590
+ isSameList = false ;
2591
+ } else {
2592
+ for (int i = 0 ; i < _referencedIds.length; i++ ) {
2593
+ if (_referencedIds[i] != value[i]) {
2594
+ isSameList = false ;
2595
+ break ;
2596
+ }
2597
+ }
2598
+ }
2599
+ if (! isSameList) {
2587
2600
_referencedIds = value;
2588
2601
updateParentData ();
2589
2602
markParentNeedsLayout ();
0 commit comments