简体   繁体   English

RenderFlex 溢出使用 Flutter GridView

[英]RenderFlex overflow using Flutter GridView

I used a GridView.count() to display dynamic data in my app, but each of my GridView elements doesn't fully display.我使用 GridView.count() 在我的应用程序中显示动态数据,但我的每个 GridView 元素都没有完全显示。

Here is what it looks like:这是它的样子:

在此处输入图像描述

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.按照本主题的答案中的建议,我已经在 BouncingScrollPhysics 或 NeverScrollableScrollPhysics 中添加了属性 shrinkWrap 和物理属性,但您可以看到它对我不起作用。

Also, I don't want to use a fixed height because data is dynamic here.另外,我不想使用固定高度,因为这里的数据是动态的。

Thanks for helping.感谢您的帮助。

You can set custom height for grid using childAspectRatio attribute您可以使用 childAspectRatio 属性为网格设置自定义高度

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()
        )
      ],
    );

GridView children's size depends on childAspectRatio , default it is 1.0 , you can increase height by changing default childAspectRatio . GridView儿童尺寸取决于childAspectRatio ,默认为1.0 ,您可以通过更改默认childAspectRatio来增加高度。 like喜欢

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

Please try using this library, staggered_grid_view请尝试使用这个库, staggered_grid_view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM