Skip to content

Commit 0891c40

Browse files
author
fbchen
committed
add anotation
1 parent a2393f3 commit 0891c40

File tree

2 files changed

+124
-36
lines changed

2 files changed

+124
-36
lines changed

README.md

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class ExampleState extends State<Example> {
8787
id: 'box1',
8888
width: 200,
8989
height: 200,
90-
topToTop: CL.parent,
91-
rightToRight: CL.parent,
90+
topRightTo: CL.parent,
9291
child: Container(
9392
color: Colors.redAccent,
9493
alignment: Alignment.center,
@@ -99,8 +98,7 @@ class ExampleState extends State<Example> {
9998
id: 'box2',
10099
width: CL.matchConstraint,
101100
height: CL.matchConstraint,
102-
leftToLeft: 'box3',
103-
rightToRight: 'box3',
101+
centerHorizontalTo: 'box3',
104102
topToBottom: 'box3',
105103
bottomToBottom: CL.parent,
106104
child: Container(
@@ -127,8 +125,7 @@ class ExampleState extends State<Example> {
127125
id: 'box4',
128126
width: 50,
129127
height: 50,
130-
rightToRight: CL.parent,
131-
bottomToBottom: CL.parent,
128+
bottomRightTo: CL.parent,
132129
child: Container(
133130
color: Colors.redAccent,
134131
alignment: Alignment.center,
@@ -139,10 +136,9 @@ class ExampleState extends State<Example> {
139136
id: 'box5',
140137
width: 120,
141138
height: 100,
142-
center: CL.parent,
139+
centerTo: CL.parent,
143140
zIndex: 100,
144141
translate: Offset(x, y),
145-
clickPadding: const EdgeInsets.all(30),
146142
translateConstraint: true,
147143
child: GestureDetector(
148144
child: Container(
@@ -162,7 +158,7 @@ class ExampleState extends State<Example> {
162158
id: 'box6',
163159
width: 120,
164160
height: 120,
165-
centerVertical: 'box2',
161+
centerVerticalTo: 'box2',
166162
verticalBias: 0.8,
167163
leftToRight: 'box3',
168164
rightToRight: CL.parent,
@@ -176,10 +172,9 @@ class ExampleState extends State<Example> {
176172
id: 'box7',
177173
width: CL.matchConstraint,
178174
height: CL.matchConstraint,
179-
topToTop: 'box1',
180175
leftToLeft: CL.parent,
181176
rightToLeft: 'box3',
182-
bottomToBottom: CL.parent,
177+
centerVerticalTo: CL.parent,
183178
margin: const EdgeInsets.all(50),
184179
child: Container(
185180
color: Colors.lightGreen,
@@ -217,7 +212,52 @@ class ExampleState extends State<Example> {
217212
color: Colors.white,
218213
),
219214
),
220-
)
215+
),
216+
...hChain(
217+
leftToLeft: CL.parent,
218+
rightToRight: CL.parent,
219+
hChainList: [
220+
Constrained(
221+
id: 'box10',
222+
width: CL.matchConstraint,
223+
height: 200,
224+
topToTop: CL.parent,
225+
child: Container(
226+
color: Colors.redAccent,
227+
alignment: Alignment.center,
228+
child: const Text('chain item 1'),
229+
),
230+
),
231+
Constrained(
232+
id: 'box11',
233+
width: CL.matchConstraint,
234+
height: 200,
235+
topToTop: CL.parent,
236+
child: Container(
237+
color: Colors.redAccent,
238+
alignment: Alignment.center,
239+
child: const Text('chain item 2'),
240+
),
241+
),
242+
],
243+
),
244+
Constrained(
245+
id: 'box12',
246+
width: CL.matchConstraint,
247+
height: CL.matchConstraint,
248+
widthPercent: 0.5,
249+
heightPercent: 0.3,
250+
horizontalBias: 0,
251+
verticalBias: 0,
252+
centerTo: CL.parent,
253+
zIndex: 6,
254+
child: Container(
255+
color: Colors.yellow,
256+
alignment: Alignment.bottomCenter,
257+
child: const Text(
258+
'percentage layout, width: 50% of parent, height: 30% of parent'),
259+
),
260+
),
221261
],
222262
),
223263
),

lib/constrait_layout/constraint_layout.dart

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ List<Constrained> vChain({
153153
return [];
154154
}
155155

156+
/// Wrapper constraints design for simplicity of use, it will eventually convert to base constraints.
157+
const Object _wrapperConstraints = Object();
158+
const Object _baseConstraints = Object();
159+
156160
bool _debugEnsureNotEmptyString(String name, String? value) {
157161
if (value != null && value.trim().isEmpty) {
158162
throw ConstraintLayoutException(
@@ -219,17 +223,29 @@ class _ConstraintBoxData extends ContainerBoxParentData<RenderBox> {
219223
EdgeInsets? margin;
220224
EdgeInsets? goneMargin;
221225

222-
/// There are only basic constraints here
226+
/// There are only base constraints here
227+
228+
@_baseConstraints
223229
String? leftToLeft;
230+
@_baseConstraints
224231
String? leftToRight;
232+
@_baseConstraints
225233
String? rightToLeft;
234+
@_baseConstraints
226235
String? rightToRight;
236+
@_baseConstraints
227237
String? topToTop;
238+
@_baseConstraints
228239
String? topToBottom;
240+
@_baseConstraints
229241
String? bottomToTop;
242+
@_baseConstraints
230243
String? bottomToBottom;
244+
@_baseConstraints
231245
String? baselineToTop;
246+
@_baseConstraints
232247
String? baselineToBottom;
248+
@_baseConstraints
233249
String? baselineToBaseline;
234250

235251
TextBaseline? textBaseline;
@@ -261,16 +277,27 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
261277
final EdgeInsets goneMargin;
262278

263279
/// These are the base constraints constraint on sibling id or CL.parent
280+
@_baseConstraints
264281
final String? leftToLeft;
282+
@_baseConstraints
265283
final String? leftToRight;
284+
@_baseConstraints
266285
final String? rightToLeft;
286+
@_baseConstraints
267287
final String? rightToRight;
288+
@_baseConstraints
268289
final String? topToTop;
290+
@_baseConstraints
269291
final String? topToBottom;
292+
@_baseConstraints
270293
final String? bottomToTop;
294+
@_baseConstraints
271295
final String? bottomToBottom;
296+
@_baseConstraints
272297
final String? baselineToTop;
298+
@_baseConstraints
273299
final String? baselineToBottom;
300+
@_baseConstraints
274301
final String? baselineToBaseline;
275302

276303
/// When setting baseline alignment, height must be wrap_content or fixed size, other vertical constraints will be illegal.
@@ -297,24 +324,34 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
297324
final double verticalBias;
298325

299326
/// These are wrapper constraints for simplicity of use, which will eventually convert to base constraints.
327+
@_wrapperConstraints
300328
final String? topLeftTo;
329+
@_wrapperConstraints
301330
final String? topCenterTo;
331+
@_wrapperConstraints
302332
final String? topRightTo;
333+
@_wrapperConstraints
303334
final String? centerLeftTo;
335+
@_wrapperConstraints
304336
final String? centerTo;
337+
@_wrapperConstraints
305338
final String? centerRightTo;
339+
@_wrapperConstraints
306340
final String? bottomLeftTo;
341+
@_wrapperConstraints
307342
final String? bottomCenterTo;
343+
@_wrapperConstraints
308344
final String? bottomRightTo;
345+
@_wrapperConstraints
309346
final String? centerHorizontalTo;
347+
@_wrapperConstraints
310348
final String? centerVerticalTo;
311349

312350
/// TODO support chain
313351
/// final ChainStyle? chainStyle;
314352
/// TODO support circle positioned
315353
/// TODO support dimension ratio
316354
/// TODO support barrier
317-
/// TODO support guideline
318355
/// TODO consider flow
319356
/// group is pointless
320357
@@ -324,17 +361,17 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
324361
this.id,
325362
required this.width,
326363
required this.height,
327-
this.leftToLeft,
328-
this.leftToRight,
329-
this.rightToLeft,
330-
this.rightToRight,
331-
this.topToTop,
332-
this.topToBottom,
333-
this.bottomToTop,
334-
this.bottomToBottom,
335-
this.baselineToTop,
336-
this.baselineToBottom,
337-
this.baselineToBaseline,
364+
@_baseConstraints this.leftToLeft,
365+
@_baseConstraints this.leftToRight,
366+
@_baseConstraints this.rightToLeft,
367+
@_baseConstraints this.rightToRight,
368+
@_baseConstraints this.topToTop,
369+
@_baseConstraints this.topToBottom,
370+
@_baseConstraints this.bottomToTop,
371+
@_baseConstraints this.bottomToBottom,
372+
@_baseConstraints this.baselineToTop,
373+
@_baseConstraints this.baselineToBottom,
374+
@_baseConstraints this.baselineToBaseline,
338375
this.clickPadding = EdgeInsets.zero,
339376
this.visibility = CL.visible,
340377
this.margin = EdgeInsets.zero,
@@ -347,17 +384,17 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
347384
this.heightPercent = 1,
348385
this.horizontalBias = 0.5,
349386
this.verticalBias = 0.5,
350-
this.topLeftTo,
351-
this.topCenterTo,
352-
this.topRightTo,
353-
this.centerLeftTo,
354-
this.centerTo,
355-
this.centerRightTo,
356-
this.bottomLeftTo,
357-
this.bottomCenterTo,
358-
this.bottomRightTo,
359-
this.centerHorizontalTo,
360-
this.centerVerticalTo,
387+
@_wrapperConstraints this.topLeftTo,
388+
@_wrapperConstraints this.topCenterTo,
389+
@_wrapperConstraints this.topRightTo,
390+
@_wrapperConstraints this.centerLeftTo,
391+
@_wrapperConstraints this.centerTo,
392+
@_wrapperConstraints this.centerRightTo,
393+
@_wrapperConstraints this.bottomLeftTo,
394+
@_wrapperConstraints this.bottomCenterTo,
395+
@_wrapperConstraints this.bottomRightTo,
396+
@_wrapperConstraints this.centerHorizontalTo,
397+
@_wrapperConstraints this.centerVerticalTo,
361398
}) : assert(child is! Constrained,
362399
'Constrained can not be wrapped with Constrained.'),
363400
assert(child is! Guideline,
@@ -419,16 +456,27 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
419456
assert(_debugEnsurePercent('horizontalBias', horizontalBias));
420457
assert(_debugEnsurePercent('verticalBias', verticalBias));
421458

459+
@_baseConstraints
422460
String? leftToLeft = this.leftToLeft;
461+
@_baseConstraints
423462
String? leftToRight = this.leftToRight;
463+
@_baseConstraints
424464
String? rightToLeft = this.rightToLeft;
465+
@_baseConstraints
425466
String? rightToRight = this.rightToRight;
467+
@_baseConstraints
426468
String? topToTop = this.topToTop;
469+
@_baseConstraints
427470
String? topToBottom = this.topToBottom;
471+
@_baseConstraints
428472
String? bottomToTop = this.bottomToTop;
473+
@_baseConstraints
429474
String? bottomToBottom = this.bottomToBottom;
475+
@_baseConstraints
430476
String? baselineToTop = this.baselineToTop;
477+
@_baseConstraints
431478
String? baselineToBottom = this.baselineToBottom;
479+
@_baseConstraints
432480
String? baselineToBaseline = this.baselineToBaseline;
433481

434482
/// Convert wrapper constraints first

0 commit comments

Comments
 (0)