How To Make A Staggered Grid View With Varying Image Height In Flutter?
I wanted to have a staggered grid view with Card
widgets, I want the height of the card to be dependent of the height of the image being loaded.
Since my build method is too long, here is my code for my card view in gist:
https://gist.github.com/brendoncheung/2026a64410eddde20fa8ec740bbb9d84
The SizedBox
on line 7 is what I believe is making the card to have a constant height, but if I remove the SizedBox
it crashes.
If I remove the SizedBox
, then I will get this error:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I have made sure that the parents of all the Column
and Row
widget doesn't have a unbound constraint.
Here is my StaggeredGridView
code:
@override
Widget build(BuildContext context) {
return StaggeredGridView.countBuilder(
crossAxisCount: 2,
itemCount: items.length,
itemBuilder: (context, index) => ItemWidget(
item: items[index],
onTap: (item) => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => DetailItemScreen(
item: item,
)))),
staggeredTileBuilder: (index) => StaggeredTile.fit(1),
);
}
This 2 images below is the card widget, and the other one is with the debug paint on,
Answer
With comparison of my StaggeredGridView
settings with yours only thing that's different, is mine has this two settings which help fix viewport issue.
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
But I agree sized box is probably making height of same size.
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?