Skip to content

Commit 6958536

Browse files
author
fbchen
committed
constraints and widgets separation
1 parent a738421 commit 6958536

File tree

3 files changed

+325
-121
lines changed

3 files changed

+325
-121
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ConstraintLayout will only be measured once, This results in extremely high layo
2828
8. translate
2929
9. percentage layout
3030
10. guideline
31+
11. constraints and widgets separation
3132

3233
Coming soon:
3334

@@ -74,6 +75,7 @@ class ExampleState extends State<Example> {
7475
double x = 0;
7576
double y = 0;
7677

78+
ConstraintId box0 = ConstraintId();
7779
ConstraintId box1 = ConstraintId();
7880
ConstraintId box2 = ConstraintId();
7981
ConstraintId box3 = ConstraintId();
@@ -92,22 +94,43 @@ class ExampleState extends State<Example> {
9294
home: Scaffold(
9395
backgroundColor: Colors.black,
9496
body: ConstraintLayout(
97+
// Constraints can be separated from widgets
98+
childConstraints: [
99+
Constraint(
100+
id: box0,
101+
width: 200,
102+
height: 200,
103+
bottomLeftTo: parent,
104+
zIndex: 20,
105+
)
106+
],
95107
children: [
108+
Container(
109+
color: Colors.redAccent,
110+
alignment: Alignment.center,
111+
child: const Text('box0'),
112+
).applyConstraintId(
113+
id: box0, // Constraints can be separated from widgets
114+
),
96115
Container(
97116
color: Colors.redAccent,
98117
alignment: Alignment.center,
99118
child: const Text('box1'),
100-
).applyConstraint(
101-
id: box1,
102-
width: 200,
103-
height: 100,
104-
topRightTo: parent,
119+
).apply(
120+
constraint: Constraint(
121+
// Constraints set with widgets
122+
id: box1,
123+
width: 200,
124+
height: 100,
125+
topRightTo: parent,
126+
),
105127
),
106128
Container(
107129
color: Colors.blue,
108130
alignment: Alignment.center,
109131
child: const Text('box2'),
110132
).applyConstraint(
133+
// Constraints set with widgets easy way
111134
id: box2,
112135
width: matchConstraint,
113136
height: matchConstraint,
@@ -207,7 +230,7 @@ class ExampleState extends State<Example> {
207230
baseline: box7.baseline,
208231
left: box7.left,
209232
),
210-
...hChain(
233+
...horizontalChain(
211234
centerHorizontalTo: parent,
212235
hChainList: [
213236
Container(
@@ -245,7 +268,6 @@ class ExampleState extends State<Example> {
245268
horizontalBias: 0,
246269
verticalBias: 0,
247270
centerTo: parent,
248-
zIndex: 6,
249271
),
250272
],
251273
),

0 commit comments

Comments
 (0)