@@ -9,203 +9,51 @@ class Example extends StatefulWidget {
99}
1010
1111class ExampleState extends State <Example > {
12- double x = 0 ;
13- double y = 0 ;
14-
15- ConstraintId box0 = ConstraintId ();
16- ConstraintId box1 = ConstraintId ();
17- ConstraintId box2 = ConstraintId ();
18- ConstraintId box3 = ConstraintId ();
19- ConstraintId box4 = ConstraintId ();
20- ConstraintId box5 = ConstraintId ();
21- ConstraintId box6 = ConstraintId ();
22- ConstraintId box7 = ConstraintId ();
23- ConstraintId box8 = ConstraintId ();
24- ConstraintId box9 = ConstraintId ();
25- ConstraintId box10 = ConstraintId ();
26- ConstraintId box11 = ConstraintId ();
12+ ConstraintId left = ConstraintId ();
13+ ConstraintId right = ConstraintId ();
14+ ConstraintId guideline = ConstraintId ();
2715
2816 @override
2917 Widget build (BuildContext context) {
3018 return MaterialApp (
3119 home: Scaffold (
32- backgroundColor: Colors .black,
3320 body: ConstraintLayout (
34- // Constraints can be separated from widgets
35- childConstraints: [
36- Constraint (
37- id: box0,
38- width: 200 ,
39- height: 200 ,
40- bottomLeftTo: parent,
41- zIndex: 20 ,
42- )
43- ],
4421 children: [
4522 Container (
46- color: Colors .redAccent,
47- alignment: Alignment .center,
48- child: const Text ('box0' ),
49- ).applyConstraintId (
50- id: box0, // Constraints can be separated from widgets
51- ),
52- Container (
53- color: Colors .redAccent,
54- alignment: Alignment .center,
55- child: const Text ('box1' ),
56- ).apply (
57- constraint: Constraint (
58- // Constraints set with widgets
59- id: box1,
60- width: 200 ,
61- height: 100 ,
62- topRightTo: parent,
63- ),
64- ),
65- Container (
66- color: Colors .blue,
67- alignment: Alignment .center,
68- child: const Text ('box2' ),
23+ color: const Color (0xFF005BBB ),
6924 ).applyConstraint (
70- // Constraints set with widgets easy way
71- id: box2,
72- width: matchConstraint,
25+ id: left,
26+ width: matchParent,
7327 height: matchConstraint,
74- centerHorizontalTo: box3,
75- top: box3.bottom,
76- bottom: parent.bottom,
28+ top: parent.top,
29+ bottom: guideline.top,
7730 ),
78- Container (
79- color: Colors .orange,
80- width: 200 ,
81- height: 150 ,
82- alignment: Alignment .center,
83- child: const Text ('box3' ),
84- ).applyConstraint (
85- id: box3,
86- width: wrapContent,
87- height: wrapContent,
88- right: box1.left,
89- top: box1.bottom,
31+ Guideline (
32+ id: guideline,
33+ horizontal: true ,
34+ guidelinePercent: 0.5 ,
9035 ),
9136 Container (
92- color: Colors .redAccent,
93- alignment: Alignment .center,
94- child: const Text ('box4' ),
37+ color: const Color (0xFFFFD500 ),
9538 ).applyConstraint (
96- id: box4,
97- width: 50 ,
98- height: 50 ,
99- bottomRightTo: parent,
100- ),
101- GestureDetector (
102- child: Container (
103- color: Colors .pink,
104- alignment: Alignment .center,
105- child: const Text ('box5 draggable' ),
106- ),
107- onPanUpdate: (details) {
108- setState (() {
109- x += details.delta.dx;
110- y += details.delta.dy;
111- });
112- },
113- ).applyConstraint (
114- id: box5,
115- width: 120 ,
116- height: 100 ,
117- centerTo: parent,
118- zIndex: 100 ,
119- translate: Offset (x, y),
120- translateConstraint: true ,
121- ),
122- Container (
123- color: Colors .lightGreen,
124- alignment: Alignment .center,
125- child: const Text ('box6' ),
126- ).applyConstraint (
127- id: box6,
128- width: 120 ,
129- height: 120 ,
130- centerVerticalTo: box2,
131- verticalBias: 0.8 ,
132- left: box3.right,
133- right: parent.right,
134- ),
135- Container (
136- color: Colors .lightGreen,
137- alignment: Alignment .center,
138- child: const Text ('box7' ),
139- ).applyConstraint (
140- id: box7,
141- width: matchConstraint,
39+ id: right,
40+ width: matchParent,
14241 height: matchConstraint,
143- left: parent.left,
144- right: box3.left,
145- centerVerticalTo: parent,
146- margin: const EdgeInsets .all (50 ),
147- ),
148- Container (
149- color: Colors .cyan,
150- alignment: Alignment .center,
151- child: const Text ('child[7] pinned to the top right' ),
152- ).applyConstraint (
153- width: 200 ,
154- height: 100 ,
155- left: box5.right,
156- bottom: box5.top,
42+ top: guideline.bottom,
43+ bottom: parent.bottom,
15744 ),
15845 const Text (
159- 'box9 baseline to box7 ' ,
46+ 'Stand with the people of Ukraine ' ,
16047 style: TextStyle (
48+ fontSize: 40 ,
16149 color: Colors .white,
16250 ),
16351 ).applyConstraint (
164- id: box9,
16552 width: wrapContent,
16653 height: wrapContent,
167- baseline: box7.baseline,
168- left: box7.left,
169- ),
170- ...horizontalChain (
17154 centerHorizontalTo: parent,
172- hChainList: [
173- Container (
174- color: Colors .redAccent,
175- alignment: Alignment .center,
176- child: const Text ('chain item 1' ),
177- ).applyConstraint (
178- id: box10,
179- width: matchConstraint,
180- height: 200 ,
181- top: parent.top,
182- ),
183- Container (
184- color: Colors .redAccent,
185- alignment: Alignment .center,
186- child: const Text ('chain item 2' ),
187- ).applyConstraint (
188- id: box11,
189- width: matchConstraint,
190- height: 200 ,
191- top: parent.top,
192- ),
193- ],
194- ),
195- Container (
196- color: Colors .yellow,
197- alignment: Alignment .bottomCenter,
198- child: const Text (
199- 'percentage layout\n width: 50% of parent\n height: 30% of parent' ),
200- ).applyConstraint (
201- width: matchConstraint,
202- height: matchConstraint,
203- widthPercent: 0.5 ,
204- heightPercent: 0.3 ,
205- horizontalBias: 0 ,
206- verticalBias: 0 ,
207- centerTo: parent,
208- ),
55+ bottom: guideline.bottom,
56+ )
20957 ],
21058 ),
21159 ),
0 commit comments