@@ -19,8 +19,6 @@ ConstraintLayout will only be measured once, This results in extremely high layo
19
19
9 . baselineToTop
20
20
10 . baselineToBottom
21
21
11 . baselineToBaseline
22
- 12 . width、height can be set: CL.matchParent、CL.wrapContent、CL.matchConstraint、fixed size
23
- 13 . center、centerHorizontal、centerVertical
24
22
2 . margin and goneMargin
25
23
3 . clickPadding (quickly expand the click area of child elements without changing their actual size)
26
24
4 . visibility control
@@ -76,6 +74,18 @@ class ExampleState extends State<Example> {
76
74
double x = 0;
77
75
double y = 0;
78
76
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
+
79
89
@override
80
90
Widget build(BuildContext context) {
81
91
return MaterialApp(
@@ -84,35 +94,35 @@ class ExampleState extends State<Example> {
84
94
body : ConstraintLayout(
85
95
children : [
86
96
Constrained(
87
- id : ' box1' ,
97
+ id : box1,
88
98
width : 200,
89
99
height : 200,
90
- topRightTo : CL. parent,
100
+ topRightTo : parent,
91
101
child : Container(
92
102
color : Colors.redAccent,
93
103
alignment : Alignment.center,
94
104
child : const Text('box1'),
95
105
),
96
106
),
97
107
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 ,
104
114
child : Container(
105
115
color : Colors.blue,
106
116
alignment : Alignment.center,
107
117
child : const Text('box2'),
108
118
),
109
119
),
110
120
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 ,
116
126
child : Container(
117
127
color : Colors.orange,
118
128
width : 200,
@@ -122,21 +132,21 @@ class ExampleState extends State<Example> {
122
132
),
123
133
),
124
134
Constrained(
125
- id : ' box4' ,
135
+ id : box4,
126
136
width : 50,
127
137
height : 50,
128
- bottomRightTo : CL. parent,
138
+ bottomRightTo : parent,
129
139
child : Container(
130
140
color : Colors.redAccent,
131
141
alignment : Alignment.center,
132
142
child : const Text('box4'),
133
143
),
134
144
),
135
145
Constrained(
136
- id : ' box5' ,
146
+ id : box5,
137
147
width : 120,
138
148
height : 100,
139
- centerTo : CL. parent,
149
+ centerTo : parent,
140
150
zIndex : 100,
141
151
translate : Offset(x, y),
142
152
translateConstraint : true,
@@ -155,26 +165,26 @@ class ExampleState extends State<Example> {
155
165
),
156
166
),
157
167
Constrained(
158
- id : ' box6' ,
168
+ id : box6,
159
169
width : 120,
160
170
height : 120,
161
- centerVerticalTo : ' box2' ,
171
+ centerVerticalTo : box2,
162
172
verticalBias : 0.8,
163
- leftToRight : ' box3' ,
164
- rightToRight : CL. parent,
173
+ left : box3.right ,
174
+ right : parent.right ,
165
175
child : Container(
166
176
color : Colors.lightGreen,
167
177
alignment : Alignment.center,
168
178
child : const Text('box6'),
169
179
),
170
180
),
171
181
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,
178
188
margin : const EdgeInsets.all(50),
179
189
child : Container(
180
190
color : Colors.lightGreen,
@@ -185,54 +195,53 @@ class ExampleState extends State<Example> {
185
195
Constrained(
186
196
width : 200,
187
197
height : 100,
188
- leftToRight : ' box5' ,
189
- bottomToTop : ' box5' ,
198
+ left : box5.right ,
199
+ bottom : box5.top ,
190
200
child : Container(
191
201
color : Colors.cyan,
192
202
alignment : Alignment.center,
193
203
child : const Text('child[7] pinned to the top right'),
194
204
),
195
205
),
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 ,
201
211
202
212
/// when setting baseline alignment, height must be wrap_content or fixed size
203
213
/// other vertical constraints will be ignored
204
214
/// Warning :
205
215
/// Due to a bug in the flutter framework, baseline alignment may not take effect in debug mode
206
216
/// See https://github.com/flutter/flutter/issues/101179
207
217
208
- leftToLeft : ' box7' ,
209
- child : Text(
218
+ left : box7.left ,
219
+ child : const Text(
210
220
' box9 baseline to box7' ,
211
221
style : TextStyle(
212
222
color : Colors.white,
213
223
),
214
224
),
215
225
),
216
226
...hChain(
217
- leftToLeft : CL.parent,
218
- rightToRight : CL.parent,
227
+ centerHorizontalTo : parent,
219
228
hChainList : [
220
229
Constrained(
221
- id : ' box10' ,
222
- width : CL. matchConstraint,
230
+ id : box10,
231
+ width : matchConstraint,
223
232
height : 200,
224
- topToTop : CL. parent,
233
+ top : parent.top ,
225
234
child : Container(
226
235
color : Colors.redAccent,
227
236
alignment : Alignment.center,
228
237
child : const Text('chain item 1'),
229
238
),
230
239
),
231
240
Constrained(
232
- id : ' box11' ,
233
- width : CL. matchConstraint,
241
+ id : box11,
242
+ width : matchConstraint,
234
243
height : 200,
235
- topToTop : CL. parent,
244
+ top : parent.top ,
236
245
child : Container(
237
246
color : Colors.redAccent,
238
247
alignment : Alignment.center,
@@ -242,14 +251,13 @@ class ExampleState extends State<Example> {
242
251
],
243
252
),
244
253
Constrained(
245
- id : ' box12' ,
246
- width : CL.matchConstraint,
247
- height : CL.matchConstraint,
254
+ width : matchConstraint,
255
+ height : matchConstraint,
248
256
widthPercent : 0.5,
249
257
heightPercent : 0.3,
250
258
horizontalBias : 0,
251
259
verticalBias : 0,
252
- centerTo : CL. parent,
260
+ centerTo : parent,
253
261
zIndex : 6,
254
262
child : Container(
255
263
color : Colors.yellow,
0 commit comments