Skip to content

Commit 58066df

Browse files
committed
enhance grid again
1 parent f1165c8 commit 58066df

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

lib/src/constraint_layout.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ List<Widget> constraintGrid({
9090
required Widget Function(int index) itemBuilder,
9191
EdgeInsets Function(int index)? itemMarginBuilder,
9292
EdgeInsets margin = EdgeInsets.zero,
93+
CLVisibility visibility = visible,
94+
Offset translate = Offset.zero,
95+
bool translateConstraint = false,
96+
int? zIndex,
9397
}) {
9498
assert(itemCount > 0);
9599
assert(columnCount > 0);
@@ -124,8 +128,10 @@ List<Widget> constraintGrid({
124128
return margin;
125129
}
126130

131+
List<ConstraintId> childIds = [];
127132
for (int i = 0; i < itemCount; i++) {
128133
ConstraintId itemId = ConstraintId(id.id + '_grid_item_$i');
134+
childIds.add(itemId);
129135
Widget widget = itemBuilder(i);
130136
Size? itemSize = itemSizeBuilder?.call(i);
131137
widgets.add(Constrained(
@@ -136,6 +142,9 @@ List<Widget> constraintGrid({
136142
height: itemHeight ?? itemSize!.height,
137143
left: leftAnchor,
138144
top: topAnchor,
145+
zIndex: zIndex,
146+
translate: translate,
147+
visibility: visibility,
139148
margin: calculateItemMargin(
140149
i, columnCount, itemMarginBuilder?.call(i) ?? EdgeInsets.zero),
141150
),
@@ -146,6 +155,50 @@ List<Widget> constraintGrid({
146155
topAnchor = itemId.bottom;
147156
}
148157
}
158+
159+
Barrier leftBarrier = Barrier(
160+
id: ConstraintId(id.id + '_left_barrier'),
161+
direction: BarrierDirection.left,
162+
referencedIds: childIds,
163+
);
164+
165+
Barrier topBarrier = Barrier(
166+
id: ConstraintId(id.id + '_top_barrier'),
167+
direction: BarrierDirection.top,
168+
referencedIds: childIds,
169+
);
170+
171+
Barrier rightBarrier = Barrier(
172+
id: ConstraintId(id.id + '_right_barrier'),
173+
direction: BarrierDirection.right,
174+
referencedIds: childIds,
175+
);
176+
177+
Barrier bottomBarrier = Barrier(
178+
id: ConstraintId(id.id + '_bottom_barrier'),
179+
direction: BarrierDirection.bottom,
180+
referencedIds: childIds,
181+
);
182+
183+
widgets.add(leftBarrier);
184+
widgets.add(topBarrier);
185+
widgets.add(rightBarrier);
186+
widgets.add(bottomBarrier);
187+
188+
widgets.add(const SizedBox().applyConstraint(
189+
id: id,
190+
width: matchConstraint,
191+
height: matchConstraint,
192+
left: leftBarrier.id.left,
193+
top: topBarrier.id.top,
194+
right: rightBarrier.id.right,
195+
bottom: bottomBarrier.id.bottom,
196+
zIndex: -1,
197+
translate: translate,
198+
translateConstraint: translateConstraint,
199+
visibility: visibility,
200+
));
201+
149202
return widgets;
150203
}
151204

0 commit comments

Comments
 (0)