@@ -19,8 +19,6 @@ ConstraintLayout will only be measured once, This results in extremely high layo
1919 9 . baselineToTop
2020 10 . baselineToBottom
2121 11 . baselineToBaseline
22- 12 . width、height can be set: CL.matchParent、CL.wrapContent、CL.matchConstraint、fixed size
23- 13 . center、centerHorizontal、centerVertical
24222 . margin and goneMargin
25233 . clickPadding (quickly expand the click area of child elements without changing their actual size)
26244 . visibility control
@@ -76,6 +74,18 @@ class ExampleState extends State<Example> {
7674 double x = 0;
7775 double y = 0;
7876
77+ ConstraintId box1 = ConstraintId();
78+ ConstraintId box2 = ConstraintId();
79+ ConstraintId box3 = ConstraintId();
80+ ConstraintId box4 = ConstraintId();
81+ ConstraintId box5 = ConstraintId();
82+ ConstraintId box6 = ConstraintId();
83+ ConstraintId box7 = ConstraintId();
84+ ConstraintId box8 = ConstraintId();
85+ ConstraintId box9 = ConstraintId();
86+ ConstraintId box10 = ConstraintId();
87+ ConstraintId box11 = ConstraintId();
88+
7989 @override
8090 Widget build(BuildContext context) {
8191 return MaterialApp(
@@ -84,35 +94,35 @@ class ExampleState extends State<Example> {
8494 body : ConstraintLayout(
8595 children : [
8696 Constrained(
87- id : ' box1' ,
97+ id : box1,
8898 width : 200,
8999 height : 200,
90- topRightTo : CL. parent,
100+ topRightTo : parent,
91101 child : Container(
92102 color : Colors.redAccent,
93103 alignment : Alignment.center,
94104 child : const Text('box1'),
95105 ),
96106 ),
97107 Constrained(
98- id : ' box2' ,
99- width : CL. matchConstraint,
100- height : CL. matchConstraint,
101- centerHorizontalTo : ' box3' ,
102- topToBottom : ' box3' ,
103- bottomToBottom : CL. parent,
108+ id : box2,
109+ width : matchConstraint,
110+ height : matchConstraint,
111+ centerHorizontalTo : box3,
112+ top : box3.bottom ,
113+ bottom : parent.bottom ,
104114 child : Container(
105115 color : Colors.blue,
106116 alignment : Alignment.center,
107117 child : const Text('box2'),
108118 ),
109119 ),
110120 Constrained(
111- id : ' box3' ,
112- width : CL. wrapContent,
113- height : CL. wrapContent,
114- rightToLeft : ' box1' ,
115- topToBottom : ' box1' ,
121+ id : box3,
122+ width : wrapContent,
123+ height : wrapContent,
124+ right : box1.left ,
125+ top : box1.bottom ,
116126 child : Container(
117127 color : Colors.orange,
118128 width : 200,
@@ -122,21 +132,21 @@ class ExampleState extends State<Example> {
122132 ),
123133 ),
124134 Constrained(
125- id : ' box4' ,
135+ id : box4,
126136 width : 50,
127137 height : 50,
128- bottomRightTo : CL. parent,
138+ bottomRightTo : parent,
129139 child : Container(
130140 color : Colors.redAccent,
131141 alignment : Alignment.center,
132142 child : const Text('box4'),
133143 ),
134144 ),
135145 Constrained(
136- id : ' box5' ,
146+ id : box5,
137147 width : 120,
138148 height : 100,
139- centerTo : CL. parent,
149+ centerTo : parent,
140150 zIndex : 100,
141151 translate : Offset(x, y),
142152 translateConstraint : true,
@@ -155,26 +165,26 @@ class ExampleState extends State<Example> {
155165 ),
156166 ),
157167 Constrained(
158- id : ' box6' ,
168+ id : box6,
159169 width : 120,
160170 height : 120,
161- centerVerticalTo : ' box2' ,
171+ centerVerticalTo : box2,
162172 verticalBias : 0.8,
163- leftToRight : ' box3' ,
164- rightToRight : CL. parent,
173+ left : box3.right ,
174+ right : parent.right ,
165175 child : Container(
166176 color : Colors.lightGreen,
167177 alignment : Alignment.center,
168178 child : const Text('box6'),
169179 ),
170180 ),
171181 Constrained(
172- id : ' box7' ,
173- width : CL. matchConstraint,
174- height : CL. matchConstraint,
175- leftToLeft : CL. parent,
176- rightToLeft : ' box3' ,
177- centerVerticalTo : CL. parent,
182+ id : box7,
183+ width : matchConstraint,
184+ height : matchConstraint,
185+ left : parent.left ,
186+ right : box3.left ,
187+ centerVerticalTo : parent,
178188 margin : const EdgeInsets.all(50),
179189 child : Container(
180190 color : Colors.lightGreen,
@@ -185,54 +195,53 @@ class ExampleState extends State<Example> {
185195 Constrained(
186196 width : 200,
187197 height : 100,
188- leftToRight : ' box5' ,
189- bottomToTop : ' box5' ,
198+ left : box5.right ,
199+ bottom : box5.top ,
190200 child : Container(
191201 color : Colors.cyan,
192202 alignment : Alignment.center,
193203 child : const Text('child[7] pinned to the top right'),
194204 ),
195205 ),
196- const Constrained(
197- id : ' box9' ,
198- width : CL. wrapContent,
199- height : CL. wrapContent,
200- baselineToBaseline : ' box7' ,
206+ Constrained(
207+ id : box9,
208+ width : wrapContent,
209+ height : wrapContent,
210+ baseline : box7.baseline ,
201211
202212 /// when setting baseline alignment, height must be wrap_content or fixed size
203213 /// other vertical constraints will be ignored
204214 /// Warning :
205215 /// Due to a bug in the flutter framework, baseline alignment may not take effect in debug mode
206216 /// See https://github.com/flutter/flutter/issues/101179
207217
208- leftToLeft : ' box7' ,
209- child : Text(
218+ left : box7.left ,
219+ child : const Text(
210220 ' box9 baseline to box7' ,
211221 style : TextStyle(
212222 color : Colors.white,
213223 ),
214224 ),
215225 ),
216226 ...hChain(
217- leftToLeft : CL.parent,
218- rightToRight : CL.parent,
227+ centerHorizontalTo : parent,
219228 hChainList : [
220229 Constrained(
221- id : ' box10' ,
222- width : CL. matchConstraint,
230+ id : box10,
231+ width : matchConstraint,
223232 height : 200,
224- topToTop : CL. parent,
233+ top : parent.top ,
225234 child : Container(
226235 color : Colors.redAccent,
227236 alignment : Alignment.center,
228237 child : const Text('chain item 1'),
229238 ),
230239 ),
231240 Constrained(
232- id : ' box11' ,
233- width : CL. matchConstraint,
241+ id : box11,
242+ width : matchConstraint,
234243 height : 200,
235- topToTop : CL. parent,
244+ top : parent.top ,
236245 child : Container(
237246 color : Colors.redAccent,
238247 alignment : Alignment.center,
@@ -242,14 +251,13 @@ class ExampleState extends State<Example> {
242251 ],
243252 ),
244253 Constrained(
245- id : ' box12' ,
246- width : CL.matchConstraint,
247- height : CL.matchConstraint,
254+ width : matchConstraint,
255+ height : matchConstraint,
248256 widthPercent : 0.5,
249257 heightPercent : 0.3,
250258 horizontalBias : 0,
251259 verticalBias : 0,
252- centerTo : CL. parent,
260+ centerTo : parent,
253261 zIndex : 6,
254262 child : Container(
255263 color : Colors.yellow,
0 commit comments