@@ -93,164 +93,151 @@ class ExampleState extends State<Example> {
93
93
backgroundColor : Colors.black,
94
94
body : ConstraintLayout(
95
95
children : [
96
- Constrained(
96
+ Container(
97
+ color : Colors.redAccent,
98
+ alignment : Alignment.center,
99
+ child : const Text('box1'),
100
+ ).applyConstraint(
97
101
id : box1,
98
102
width : 200,
99
103
height : 200,
100
104
topRightTo : parent,
101
- child : Container(
102
- color : Colors.redAccent,
103
- alignment : Alignment.center,
104
- child : const Text('box1'),
105
- ),
106
105
),
107
- Constrained(
106
+ Container(
107
+ color : Colors.blue,
108
+ alignment : Alignment.center,
109
+ child : const Text('box2'),
110
+ ).applyConstraint(
108
111
id : box2,
109
112
width : matchConstraint,
110
113
height : matchConstraint,
111
114
centerHorizontalTo : box3,
112
115
top : box3.bottom,
113
116
bottom : parent.bottom,
114
- child : Container(
115
- color : Colors.blue,
116
- alignment : Alignment.center,
117
- child : const Text('box2'),
118
- ),
119
117
),
120
- Constrained(
118
+ Container(
119
+ color : Colors.orange,
120
+ width : 200,
121
+ height : 300,
122
+ alignment : Alignment.center,
123
+ child : const Text('box3'),
124
+ ).applyConstraint(
121
125
id : box3,
122
126
width : wrapContent,
123
127
height : wrapContent,
124
128
right : box1.left,
125
129
top : box1.bottom,
126
- child : Container(
127
- color : Colors.orange,
128
- width : 200,
129
- height : 300,
130
- alignment : Alignment.center,
131
- child : const Text('box3'),
132
- ),
133
130
),
134
- Constrained(
131
+ Container(
132
+ color : Colors.redAccent,
133
+ alignment : Alignment.center,
134
+ child : const Text('box4'),
135
+ ).applyConstraint(
135
136
id : box4,
136
137
width : 50,
137
138
height : 50,
138
139
bottomRightTo : parent,
140
+ ),
141
+ GestureDetector(
139
142
child : Container(
140
- color : Colors.redAccent ,
143
+ color : Colors.pink ,
141
144
alignment : Alignment.center,
142
- child : const Text('box4 '),
145
+ child : const Text('box5 draggable '),
143
146
),
144
- ),
145
- Constrained(
147
+ onPanUpdate : (details) {
148
+ setState(() {
149
+ x += details.delta.dx;
150
+ y += details.delta.dy;
151
+ });
152
+ },
153
+ ).applyConstraint(
146
154
id : box5,
147
155
width : 120,
148
156
height : 100,
149
157
centerTo : parent,
150
158
zIndex : 100,
151
159
translate : Offset(x, y),
152
160
translateConstraint : true,
153
- child : GestureDetector(
154
- child : Container(
155
- color : Colors.pink,
156
- alignment : Alignment.center,
157
- child : const Text('box5 draggable'),
158
- ),
159
- onPanUpdate : (details) {
160
- setState(() {
161
- x += details.delta.dx;
162
- y += details.delta.dy;
163
- });
164
- },
165
- ),
166
161
),
167
- Constrained(
162
+ Container(
163
+ color : Colors.lightGreen,
164
+ alignment : Alignment.center,
165
+ child : const Text('box6'),
166
+ ).applyConstraint(
168
167
id : box6,
169
168
width : 120,
170
169
height : 120,
171
170
centerVerticalTo : box2,
172
171
verticalBias : 0.8,
173
172
left : box3.right,
174
173
right : parent.right,
175
- child : Container(
176
- color : Colors.lightGreen,
177
- alignment : Alignment.center,
178
- child : const Text('box6'),
179
- ),
180
174
),
181
- Constrained(
175
+ Container(
176
+ color : Colors.lightGreen,
177
+ alignment : Alignment.center,
178
+ child : const Text('box7'),
179
+ ).applyConstraint(
182
180
id : box7,
183
181
width : matchConstraint,
184
182
height : matchConstraint,
185
183
left : parent.left,
186
184
right : box3.left,
187
185
centerVerticalTo : parent,
188
186
margin : const EdgeInsets.all(50),
189
- child : Container(
190
- color : Colors.lightGreen,
191
- alignment : Alignment.center,
192
- child : const Text('box7'),
193
- ),
194
187
),
195
- Constrained(
188
+ Container(
189
+ color : Colors.cyan,
190
+ alignment : Alignment.center,
191
+ child : const Text('child[7] pinned to the top right'),
192
+ ).applyConstraint(
196
193
width : 200,
197
194
height : 100,
198
195
left : box5.right,
199
196
bottom : box5.top,
200
- child : Container(
201
- color : Colors.cyan,
202
- alignment : Alignment.center,
203
- child : const Text('child[7] pinned to the top right'),
204
- ),
205
197
),
206
- Constrained(
198
+ const Text(
199
+ ' box9 baseline to box7' ,
200
+ style : TextStyle(
201
+ color : Colors.white,
202
+ ),
203
+ ).applyConstraint(
207
204
id : box9,
208
205
width : wrapContent,
209
206
height : wrapContent,
210
207
baseline : box7.baseline,
211
-
212
- /// when setting baseline alignment, height must be wrap_content or fixed size
213
- /// other vertical constraints will be ignored
214
- /// Warning :
215
- /// Due to a bug in the flutter framework, baseline alignment may not take effect in debug mode
216
- /// See https://github.com/flutter/flutter/issues/101179
217
-
218
208
left : box7.left,
219
- child : const Text(
220
- ' box9 baseline to box7' ,
221
- style : TextStyle(
222
- color : Colors.white,
223
- ),
224
- ),
225
209
),
226
210
...hChain(
227
211
centerHorizontalTo : parent,
228
212
hChainList : [
229
- Constrained(
213
+ Container(
214
+ color : Colors.redAccent,
215
+ alignment : Alignment.center,
216
+ child : const Text('chain item 1'),
217
+ ).applyConstraint(
230
218
id : box10,
231
219
width : matchConstraint,
232
220
height : 200,
233
221
top : parent.top,
234
- child : Container(
235
- color : Colors.redAccent,
236
- alignment : Alignment.center,
237
- child : const Text('chain item 1'),
238
- ),
239
222
),
240
- Constrained(
223
+ Container(
224
+ color : Colors.redAccent,
225
+ alignment : Alignment.center,
226
+ child : const Text('chain item 2'),
227
+ ).applyConstraint(
241
228
id : box11,
242
229
width : matchConstraint,
243
230
height : 200,
244
231
top : parent.top,
245
- child : Container(
246
- color : Colors.redAccent,
247
- alignment : Alignment.center,
248
- child : const Text('chain item 2'),
249
- ),
250
232
),
251
233
],
252
234
),
253
- Constrained(
235
+ Container(
236
+ color : Colors.yellow,
237
+ alignment : Alignment.bottomCenter,
238
+ child : const Text(
239
+ ' percentage layout, width: 50% of parent, height: 30% of parent' ),
240
+ ).applyConstraint(
254
241
width : matchConstraint,
255
242
height : matchConstraint,
256
243
widthPercent : 0.5,
@@ -259,12 +246,6 @@ class ExampleState extends State<Example> {
259
246
verticalBias : 0,
260
247
centerTo : parent,
261
248
zIndex : 6,
262
- child : Container(
263
- color : Colors.yellow,
264
- alignment : Alignment.bottomCenter,
265
- child : const Text(
266
- ' percentage layout, width: 50% of parent, height: 30% of parent' ),
267
- ),
268
249
),
269
250
],
270
251
),
0 commit comments