@@ -111,9 +111,11 @@ List<Widget> constraintGrid({
111111 required int columnCount,
112112 double ? itemWidth,
113113 double ? itemHeight,
114- Size Function (int index)? itemSizeBuilder,
115- required Widget Function (int index) itemBuilder,
116- EdgeInsets Function (int index)? itemMarginBuilder,
114+ Size Function (int index, int rowIndex, int columnIndex)? itemSizeBuilder,
115+ required Widget Function (int index, int rowIndex, int columnIndex)
116+ itemBuilder,
117+ EdgeInsets Function (int index, int rowIndex, int columnIndex)?
118+ itemMarginBuilder,
117119 int Function (int index)? itemSpanBuilder,
118120 EdgeInsets margin = EdgeInsets .zero,
119121 CLVisibility visibility = visible,
@@ -154,12 +156,13 @@ List<Widget> constraintGrid({
154156 ConstraintId itemId = ConstraintId (id.id + '_grid_item_$i ' );
155157 allChildIds.add (itemId);
156158
157- EdgeInsets childMargin = itemMarginBuilder? .call (i) ?? EdgeInsets .zero;
158159 int itemSpan = itemSpanBuilder? .call (i) ?? 1 ;
159160 assert (itemSpan >= 1 && itemSpan <= columnCount);
160161 currentRowUsedSpanCount += itemSpan;
161162 totalUsedSpanCount += itemSpan;
162163
164+ late EdgeInsets childMargin;
165+
163166 /// New row start
164167 if (currentRowUsedSpanCount > columnCount) {
165168 currentRowIndex++ ;
@@ -180,7 +183,14 @@ List<Widget> constraintGrid({
180183 /// First column
181184 leftAnchor = left;
182185 leftChildIds.add (itemId);
183- childMargin = childMargin.add (leftMargin) as EdgeInsets ;
186+ childMargin = (itemMarginBuilder? .call (
187+ i, currentRowIndex, currentRowUsedSpanCount - 1 ) ??
188+ EdgeInsets .zero)
189+ .add (leftMargin) as EdgeInsets ;
190+ } else {
191+ childMargin = itemMarginBuilder? .call (
192+ i, currentRowIndex, currentRowUsedSpanCount - 1 ) ??
193+ EdgeInsets .zero;
184194 }
185195
186196 // First row
@@ -218,8 +228,10 @@ List<Widget> constraintGrid({
218228 }
219229 }
220230
221- Widget widget = itemBuilder (i);
222- Size ? itemSize = itemSizeBuilder? .call (i);
231+ Widget widget =
232+ itemBuilder (i, currentRowIndex, currentRowUsedSpanCount - 1 );
233+ Size ? itemSize =
234+ itemSizeBuilder? .call (i, currentRowIndex, currentRowUsedSpanCount - 1 );
223235 double width = itemWidth ?? itemSize! .width;
224236 double height = itemHeight ?? itemSize! .height;
225237
0 commit comments