首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GirdView没有出现。颤动

GirdView没有出现。颤动
EN

Stack Overflow用户
提问于 2021-05-26 11:37:37
回答 1查看 43关注 0票数 0

我想给gridview所有剩余的屏幕高度,所以我尝试将网格视图封装在一个扩展的小部件和一个灵活的小部件中,但是网格视图没有显示。

我所做的

代码语言:javascript
复制
 return Container(
  width: double.infinity,
  margin: EdgeInsets.symmetric(horizontal: 22.0, vertical: 50.0),
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Text(
        'Most Popular Search',
        style: TextStyle(
          fontSize: 32.0,
          fontWeight: FontWeight.w700,
          color: Colors.black87,
        ),
      ),
      SizedBox(height: 30.0),
      _buildPopularItems(),
      SizedBox(height: 50.0),
      Text(
        'Find an online mentor',
        style: TextStyle(
          fontSize: 32.0,
          fontWeight: FontWeight.w700,
          color: Colors.black87,
        ),
      ),
      SizedBox(height: 30.0),
      Flexible(
        child: GridView.count(
          childAspectRatio: (itemWidth / itemHeight),
          crossAxisCount: 4,
          controller: new ScrollController(keepScrollOffset: false),
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          children: [
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
          ],
        ),
      ),
    ],
  ),
);

下面的_buildPopularItems()代码

代码语言:javascript
复制
  _buildPopularItems() {
List<Widget> itemsList = [];
popularSearchList.forEach((PopularSearch popularSearch) {
  itemsList.add(PopularSkillsCard(
      imageUrl: popularSearch.imageUrl, title: popularSearch.title));
});
return SingleChildScrollView(
  child: Row(children: itemsList),
  scrollDirection: Axis.horizontal,
);

}

它给我显示了这个错误。

代码语言:javascript
复制
════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-30 19:18:01

使用展开小部件时设置flex值。这是你的密码。更改flex值以获得所需的UI。

代码语言:javascript
复制
return Container(
  width: double.infinity,
  margin: EdgeInsets.symmetric(horizontal: 22.0, vertical: 50.0),
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Expanded(
        flex: 1,
              child: Text(
          'Most Popular Search',
          style: TextStyle(
            fontSize: 32.0,
            fontWeight: FontWeight.w700,
            color: Colors.black87,
          ),
        ),
      ),
      Expanded(
        flex: 1,
              child: Text(
          'Find an online mentor',
          style: TextStyle(
            fontSize: 32.0,
            fontWeight: FontWeight.w700,
            color: Colors.black87,
          ),
        ),
      ),

      Expanded(
        flex: 6,
        child: GridView.count(
          childAspectRatio: (itemWidth / itemHeight),
          crossAxisCount: 4,
          controller: new ScrollController(keepScrollOffset: false),
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          children: [
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
            ConsultantCard(),
          ],
        ),
      ),
    ],
  ),
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67704081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档