how to get gridview item’s height and width so that i can design responsive item based on gridview’s cross axis count….
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
mainAxisSpacing: 16,
crossAxisSpacing: 8,
childAspectRatio: 0.8,
crossAxisCount: 4,//will change its based on requirnment
),
itemBuilder: (context,index){
return CustomContainer(height:??,width:??);
})
2
Answers
you can calculate these dimensions using the Mediaquery
example:
GridView’s children size depends on
childAspectRatio
. If you like to provide different size for the itemBuilder, you need to wrap with another widget that will be used to handle the parent constraints.