Skip to content

Commit 095b323

Browse files
author
fbchen
committed
add chain defination
1 parent 25cb8ae commit 095b323

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

lib/constrait_layout/constraint_layout.dart

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
7777

7878
ConstraintLayout({
7979
Key? key,
80-
List<Widget> children = const <Widget>[],
80+
required List<Widget> children,
8181
this.debugShowGuideline = false,
8282
this.debugShowPreview = false,
8383
this.debugShowClickArea = false,
@@ -126,6 +126,30 @@ class ConstraintLayout extends MultiChildRenderObjectWidget {
126126
}
127127
}
128128

129+
List<Constrained> hChain({
130+
String? leftToLeft,
131+
String? leftToRight,
132+
String? rightToLeft,
133+
String? rightToRight,
134+
required List<Constrained> hChainList,
135+
}) {
136+
assert(hChainList.length > 1,
137+
'The number of child elements in the chain must be > 1.');
138+
return [];
139+
}
140+
141+
List<Constrained> vChain({
142+
String? topToTop,
143+
String? topToBottom,
144+
String? bottomToTop,
145+
String? bottomToBottom,
146+
required List<Constrained> vChainList,
147+
}) {
148+
assert(vChainList.length > 1,
149+
'The number of child elements in the chain must be > 1.');
150+
return [];
151+
}
152+
129153
bool _debugEnsureNotEmptyString(String name, String? value) {
130154
if (value != null && value.trim().isEmpty) {
131155
throw ConstraintLayoutException(
@@ -208,7 +232,6 @@ class _ConstraintBoxData extends ContainerBoxParentData<RenderBox> {
208232
String? baselineToBottom;
209233
String? baselineToBaseline;
210234
TextBaseline? textBaseline;
211-
bool? wrappedByConstraint;
212235
}
213236

214237
class Constrained extends ParentDataWidget<_ConstraintBoxData> {
@@ -320,6 +343,9 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
320343

321344
@override
322345
void applyParentData(RenderObject renderObject) {
346+
assert(renderObject is! _InternalBox,
347+
'Guideline, Barrier can not be wrapped with Constrained.');
348+
323349
// bounds check
324350
assert(checkSize(width));
325351
assert(checkSize(height));
@@ -615,8 +641,6 @@ class Constrained extends ParentDataWidget<_ConstraintBoxData> {
615641
}
616642
}
617643

618-
parentData.wrappedByConstraint = true;
619-
620644
if (needsLayout) {
621645
AbstractNode? targetParent = renderObject.parent;
622646
if (targetParent is RenderObject) {
@@ -904,11 +928,6 @@ class _ConstraintRenderBox extends RenderBox
904928
if (childParentData.width == null) {
905929
throw ConstraintLayoutException(
906930
'Child elements must be wrapped with Constrained.');
907-
} else if (childParentData.wrappedByConstraint == true) {
908-
if (child is _InternalBox) {
909-
throw ConstraintLayoutException(
910-
'Guideline, Barrier can not be wrapped with Constrained.');
911-
}
912931
}
913932
}
914933
return true;

lib/example.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ class ExampleState extends State<Example> {
153153
color: Colors.white,
154154
),
155155
),
156+
),
157+
...hChain(
158+
leftToLeft: CL.parent,
159+
rightToRight: CL.parent,
160+
hChainList: [
161+
Constrained(
162+
id: 'box10',
163+
width: CL.matchConstraint,
164+
height: 200,
165+
topToTop: CL.parent,
166+
child: Container(
167+
color: Colors.redAccent,
168+
alignment: Alignment.center,
169+
child: const Text('chain item 1'),
170+
),
171+
),
172+
Constrained(
173+
id: 'box11',
174+
width: CL.matchConstraint,
175+
height: 200,
176+
topToTop: CL.parent,
177+
child: Container(
178+
color: Colors.redAccent,
179+
alignment: Alignment.center,
180+
child: const Text('chain item 2'),
181+
),
182+
),
183+
],
156184
)
157185
],
158186
),

0 commit comments

Comments
 (0)