I want to show different widgets after every 7th index and for that i have the following code. But the problem is after every 7th index i have to show a different widget from the list -'listOfWidgets' as in the code. In short after 7th index i want to show the first element of this list and then after 14th the second and so on.
Code:-
return StaggeredGridView.countBuilder(
shrinkWrap: true,
crossAxisCount: 3,
itemCount: gridTile.length,
itemBuilder: (context,index)=>index % 7 == 0 ? listOfWidgets[]: gridTile[index],
staggeredTileBuilder: (index)=>StaggeredTile.count(
1,(index%7==0)?2:1,
),
);
The answer given by @w461 is really nice and simple, the only problem is that you will skip every 7th widget of the
gridTile
widget, if it is the expected behavior then @w461's answer is perfect for this use case, if not then check out the following implementation:Final Output:
Full source code: