How to set rectangular shape to children of a grid?

150
GridView.count(
  crossAxisCount: 2,
  childAspectRatio: 0.8, // change this value for different results
  crossAxisSpacing: 5,
  mainAxisSpacing: 5,
padding: EdgeInsets.all(10.0),
  children: []
)
Share:
150
William Pineda MHA
Author by

William Pineda MHA

Updated on January 05, 2023

Comments

  • William Pineda MHA
    William Pineda MHA over 1 year

    I need to make the following page in flutter:

    enter image description here

    I need to make the following page in flutter. I already tried to do it with a SliverGrid.count(), the problem is that it is the grid that is in charge of establishing the width and height of its children. In addition, the width and height established are always the same(square shaped). Somehow I need to be able to modify the width and height and make it rectangular) so that the children are very similar to how they can be seen in the image

    I appreciate any help you can give me

    • Kaushik Chandru
      Kaushik Chandru almost 2 years
      In image all children are of same size.
    • William Pineda MHA
      William Pineda MHA almost 2 years
      Actually what I'm looking for is that the children are rectangular and not square. However, when I tried to set a height greater than the width. Flutter did not take it and all the children continued to look square
    • Yeasin Sheikh
      Yeasin Sheikh almost 2 years
      gridItem always depend on its parent width, default childAspectRatio:1 that's why we get square shape, play with childAspectRatio:width/height
  • William Pineda MHA
    William Pineda MHA almost 2 years
    Actually what I'm looking for is that the children are rectangular and not square. However, when I tried to set a height greater than the width. Flutter did not take it and all the children continued to look square
  • Kaushik Chandru
    Kaushik Chandru almost 2 years
    Add childAspectRatio and set it to value less than 0. Like 0.7 or 0.8.
  • Kaushik Chandru
    Kaushik Chandru almost 2 years
    Edited my answer. Please check