首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Listview.builder is constraints.hasBoundedHeight不是真的

Listview.builder is constraints.hasBoundedHeight不是真的
EN

Stack Overflow用户
提问于 2022-10-06 14:21:22
回答 1查看 47关注 0票数 0

你好,我正在尝试用一个listview.builder在一个包装中呈现元素,但是它给了我错误constraints.hasBoundedHeightRenderBox was not laid out: RenderShrinkWrappingViewport#fd59a relayoutBoundary=up25 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

这是我的密码:

代码语言:javascript
复制
    child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          Wrap(
            alignment: WrapAlignment.start,
            crossAxisAlignment: WrapCrossAlignment.center,
            direction: Axis.horizontal,
            spacing: 10,
            runSpacing: 15,
            children: [
              const CompatiblesInput(),
              Expanded(
                child: ListView.builder(
                  scrollDirection: Axis.horizontal,
                  shrinkWrap: true,
                  itemCount: categories.length,
                  itemBuilder: (context, index) {
                    final category = categories[index];
                    return _Category(title: category, index: index);
                  },
                ),
              ),
              const _AddCategory(),
            ],
          ),
          if (categories.isEmpty) CategoryProvider.nullCheck(),
          if (categories.length >= 5) CategoryProvider.maxCheck(),
          const SizedBox(height: 10),
        ],
     ),

这给了我上面的错误。我一直在到处搜索,每个人都说要放一个shinkWrap: true,但是它在那里,仍然不起作用。有办法解决这个问题吗?

我希望你能帮助我。提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-06 14:27:38

与其用Expanded小部件包装水平列表,不如用SizedBox包装它,如下所示:

代码语言:javascript
复制
SizedBox(
     height: 20,
     child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: categories.length,
        itemBuilder: (context, index) {
        final category = categories[index];
            return _Category(title: category, index: index);
        },
    ),
),

或者,如果不想为列表视图设置高度,可以这样做:

代码语言:javascript
复制
SingleChildScrollView(
     scrollDirection: Axis.horizontal,
     child: Row(
        children: categories.map((e) => Text('data $e')).toList(),
     ),
),
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73975425

复制
相关文章

相似问题

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