@@ -22,7 +22,7 @@ import 'package:flutter/rendering.dart';
22222323class ConstraintLayout extends MultiChildRenderObjectWidget {
2424 /// Constraints can be separated from widgets
25- final List <Constraint >? childConstraints;
25+ final List <Constraint > childConstraints;
2626
2727 final bool debugShowGuideline;
2828 final bool debugShowClickArea;
@@ -35,7 +35,7 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
3535
3636 ConstraintLayout ({
3737 Key ? key,
38- this .childConstraints,
38+ this .childConstraints = const [] ,
3939 required List <Widget > children,
4040 this .debugShowGuideline = false ,
4141 this .debugShowClickArea = false ,
@@ -113,7 +113,8 @@ List<Widget> horizontalChain({
113113 // packed
114114 }
115115
116- ConstraintId guidelineId = ConstraintId ();
116+ ConstraintId guidelineId = ConstraintId (
117+ 'internal_horizontal_chain_guideline_$i @${chainList [0 ].constraint .hashCode }' );
117118 Guideline guideline = Guideline (
118119 id: guidelineId,
119120 horizontal: false ,
@@ -276,7 +277,7 @@ bool _debugEnsureNegativePercent(String name, double? percent) {
276277 return true ;
277278}
278279
279- ConstraintId parent = ConstraintId ();
280+ ConstraintId parent = ConstraintId ('parent' );
280281const double matchConstraint = - 3.1415926 ;
281282const double matchParent = - 2.7182818 ;
282283const double wrapContent = - 0.6180339 ;
@@ -309,9 +310,9 @@ enum PercentageAnchor {
309310}
310311
311312class ConstraintId {
312- String ? name ;
313+ String id ;
313314
314- ConstraintId ({ this .name} ) {
315+ ConstraintId (this .id ) {
315316 left.id = this ;
316317 top.id = this ;
317318 right.id = this ;
@@ -340,24 +341,17 @@ class ConstraintId {
340341 if (other.runtimeType != runtimeType) {
341342 return false ;
342343 }
343- if ((other).name == null && name == null ) {
344- return false ;
345- }
346- return (other).name == name;
344+ return (other).id == id;
347345 }
348346
349347 @override
350348 int get hashCode {
351- if (name == null ) {
352- return super .hashCode;
353- } else {
354- return name.hashCode;
355- }
349+ return id.hashCode;
356350 }
357351
358352 @override
359353 String toString () {
360- return 'ConstraintId{name: $name }' ;
354+ return 'ConstraintId{name: $id }' ;
361355 }
362356}
363357
@@ -992,12 +986,10 @@ class UnConstrained extends ParentDataWidget<_ConstraintBoxData> {
992986 @override
993987 void applyParentData (RenderObject renderObject) {
994988 assert (renderObject.parent is _ConstraintRenderBox );
995- List <Constraint >? childConstraints =
989+ List <Constraint > childConstraints =
996990 (renderObject.parent as _ConstraintRenderBox )._childConstraints;
997- assert (childConstraints != null ,
998- 'Can not find Constraint for child with id $id .' );
999991 Iterable <Constraint > constraintIterable =
1000- childConstraints! .where ((element) => element.id == id);
992+ childConstraints.where ((element) => element.id == id);
1001993 assert (constraintIterable.isNotEmpty,
1002994 'Can not find Constraint for child with id $id .' );
1003995 assert (constraintIterable.length == 1 , 'Duplicate id in childConstraints.' );
@@ -1016,7 +1008,7 @@ class _ConstraintRenderBox extends RenderBox
10161008 with
10171009 ContainerRenderObjectMixin <RenderBox , _ConstraintBoxData >,
10181010 RenderBoxContainerDefaultsMixin <RenderBox , _ConstraintBoxData > {
1019- List <Constraint >? _childConstraints;
1011+ late List <Constraint > _childConstraints;
10201012 late bool _debugShowGuideline;
10211013 late bool _debugShowClickArea;
10221014 late bool _debugPrintConstraints;
@@ -1031,8 +1023,19 @@ class _ConstraintRenderBox extends RenderBox
10311023 final Map <ConstraintId , _ConstrainedNode > _tempConstrainedNodes = HashMap ();
10321024 late List <_ConstrainedNode > _paintingOrderList;
10331025
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) {
10361039 _childConstraints = value;
10371040 markNeedsLayout ();
10381041 }
@@ -1255,8 +1258,7 @@ class _ConstraintRenderBox extends RenderBox
12551258 child,
12561259 childParentData.id ??
12571260 ConstraintId (
1258- name:
1259- 'child[$childIndex ]@${child .runtimeType }@${child .hashCode }' ));
1261+ 'child[$childIndex ]@${child .runtimeType }@${child .hashCode }' ));
12601262 currentNode.parentData = childParentData;
12611263 currentNode.index = childIndex;
12621264
@@ -2583,7 +2585,18 @@ class _BarrierRenderBox extends _InternalBox {
25832585 }
25842586
25852587 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) {
25872600 _referencedIds = value;
25882601 updateParentData ();
25892602 markParentNeedsLayout ();
0 commit comments