0

I used a GridView.count() to display dynamic data in my app, but each of my GridView elements doesn't fully display.

Here is what it looks like :

enter image description here

Here is my code :

Column(
      children: [
        buildSubheadingText('Mes projets'),
        buildVerticalSpace(5.0),
        GridView.count(
          shrinkWrap: true,
          physics: BouncingScrollPhysics(),
          //physics: NeverScrollableScrollPhysics(),
          crossAxisCount: 2,
          children: ContextManager.projects.map((value) {
              return ProjectCard(project: value);
            }).toList()
        )
      ],
    ); 

I have added the attributes shrinkWrap at true and physics at BouncingScrollPhysics or NeverScrollableScrollPhysics as advised in the answers of this topic but as you can see it doesn't work for me.

Also, I don't want to use a fixed height because data is dynamic here.

Thanks for helping.

3 Answers 3

3

You can set custom height for grid using childAspectRatio attribute

Example:-

Column(
      children: [
        buildSubheadingText('Mes projets'),
        buildVerticalSpace(5.0),
        GridView.count(
          shrinkWrap: true,
          physics: BouncingScrollPhysics(),
          childAspectRatio: 2/3, //gives custom height to your grid element
          crossAxisCount: 2,
          children: ContextManager.projects.map((value) {
              return ProjectCard(project: value);
            }).toList()
        )
      ],
    );
Sign up to request clarification or add additional context in comments.

Comments

3

GridView children's size depends on childAspectRatio, default it is 1.0, you can increase height by changing default childAspectRatio. like

  child: GridView.count(
        crossAxisCount: 2,
        childAspectRatio: 1 / 1.2, //width /height

Comments

1

Please try using this library, staggered_grid_view

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.