I have the following code snippet,
GridTile(
child: Card(
elevation: 5,
child: Image.network(imageUrl, fit: BoxFit.scaleDown,),
),
),
);
producing following output..
But when I add column to my card like this…
GridTile(
child: Card(
elevation: 5,
child: Column(
children: <Widget>[
Image.network(imageUrl, fit: BoxFit.scaleDown,),
],
),
),
);
I got the below overflow issue..
What am I missing here., Is there any important layout details about Column that I need to take care of. I need column so that I can add favorite button and product description below the image. Find below the parent widget for reference.
return Scaffold(
appBar: AppBar(
title: Text('Shopify'),
),
body: GridView.builder(
itemBuilder: (context, index) => ProductItem(dummyProducts[index].title, dummyProducts[index].imageUrl),
itemCount: dummyProducts.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10
),
),
);
2
Answers
Enclosing the image in AspectRatio finally did the trick. Please find the code below.
Your images have a determined proportion (width / height ratio).
Using
gridDelegate
withchildAspectRatio
you can assign the ratio of theGridTile
inside yourGridView
.Adjust the
childAspectRatio
or adjust the images ratio.Play with this number to see the effect: