Adjust GridView child height according to the dynamic content in flutter

4,175 views
Skip to first unread message

Vipul Asri

unread,
Apr 23, 2018, 3:05:29 AM4/23/18
to Flutter Dev

How to implement this complex view in the flutter?

I am trying to implement a GridView with n columns and the child should be of a certain aspect ratio(say 1.3) but the height of the child should be (wrap content in Android terminology).

I am stuck because as fas I understand GridView's childAspectRatio:1.3 (default:1) always lays out the child in same aspect ratio but not dynamic content.

Note: Child should expand its height according to the image's height

Use case: I am trying to implement a view like below, in which image is wrapped soheight = wrap content that in case an image with stretched height can look good and form a StaggeredGridView like structure.




Dario Ielardi

unread,
Apr 23, 2018, 5:40:59 AM4/23/18
to Vipul Asri, Flutter Dev
I guess something like this can help.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Dario Ielardi

Vipul Asri

unread,
Apr 23, 2018, 5:52:03 AM4/23/18
to Flutter Dev
Already tried this library. It requires the count to be known before which is not possible in my case. You can also see the reply of Library Author on SO answer: https://stackoverflow.com/a/49838868/3140227

Ian Hickson

unread,
Apr 23, 2018, 6:57:16 PM4/23/18
to Vipul Asri, Flutter Dev
Can you elaborate on what effect you are trying to get? I'm confused by your description since you say you want a fixed aspect ratio with different height, but the picture you show has all the items having the same width. Items can't have the same width and aspect ratio but different heights, nor can they have the same aspect ratio and different heights but the same widths.
--

--
Ian Hickson

😸

Vipul Asri

unread,
Apr 23, 2018, 11:21:20 PM4/23/18
to Flutter Dev
Okay, in simple terms I want to have a grid/staggered view with a variable height that will change according to the height of the content(inc. image height and text) 

Kris Giesing

unread,
Apr 23, 2018, 11:37:06 PM4/23/18
to Vipul Asri, Flutter Dev
Based on your latest description and the screenshot, would it be fair to say you want to have a staggered grid where each element is a constant width, but variable height, such that the element preserves the natural aspect ratio of the element's child?

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.

Vipul Asri

unread,
Apr 23, 2018, 11:46:07 PM4/23/18
to Flutter Dev
Yes, that is what I want to implement. The image is loaded from network/cache and element's child should display the image preserving the image's aspect ratio.
Reply all
Reply to author
Forward
0 new messages