How to reduce the with of GridViewItems

Viewed 44

Example:

enter image description here

I want to reduce the width of this picture with childAspectRatio without knowing the values. The image above shows my layout. Is there a way to reduce the with of the GridViewItems, when I am not having the exact values of for using the child-aspect ratio properly?

Here is my code:

Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;

logger("width => $width");
logger("height => $height");

return GridView.count(
  childAspectRatio: .9/.2,
  // childAspectRatio: 6,
  // padding:EdgeInsets.only(right: 250),
  mainAxisSpacing: 10,
  crossAxisSpacing: 25,
  shrinkWrap: true,
  physics: NeverScrollableScrollPhysics(),
  crossAxisCount: width <  1510
      ?  2
      : width <  1537
          ?  3
          : 1,
  children: <Widget>[ 
        SelectCargoDropDown(), 
        CargoCampaignDropDown(), 
        FreeCargoNumberField(), 
        IdSelectionDropDown(), 
        AuthSellingDropDown(), 
        PharmacyReferenceDropDown(), 
        InformationPersonReferenceDropDown(),
],);
1 Answers

I think it's useful to insert your GridView.count in an Expanded widget.

Then it will automatically take the suitable width for the screen, even it's the same widget in the screen's width or there is another.

Related