Flutter 具有项目动态高度的ListView.builder

Flutter 具有项目动态高度的ListView.builder,flutter,flutter-listview,Flutter,Flutter Listview,我有一个包含动态内容的ListView,我希望每个项目都有基于其内容的动态高度,但如果我没有为每个项目设置固定高度,则会出现错误 包:flatter/src/rendering/sliver\u multi\u box\u adapter.dart”:失败的断言:第549行第12位:“child.hasSize”:不正确 以下是我的ListView项目生成器的完整布局: return Container( key: _key, // If I set height: 500 here i

我有一个包含动态内容的ListView,我希望每个项目都有基于其内容的动态高度,但如果我没有为每个项目设置固定高度,则会出现错误

包:flatter/src/rendering/sliver\u multi\u box\u adapter.dart”:失败的断言:第549行第12位:“child.hasSize”:不正确

以下是我的ListView项目生成器的完整布局:

return Container(
  key: _key,
  // If I set height: 500 here it works
  child: InkWell(
    onTap: () => _cardTap(_key, context, house),
      child: Card(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16.0),
        ),
        semanticContainer: true,
        clipBehavior: Clip.antiAliasWithSaveLayer,
        elevation: 4,
        child: Container(
      color: Colors.white,
      child: Stack(
        fit: StackFit.expand,
        children: <Widget>[
          ImageHelper.getHouseCategoryImage(widget.house.houseCategory),
          Padding(
            padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
            child: Align(
              alignment: Alignment.topLeft,
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Expanded(
                        child: Text(
                          widget.house.addressStreet,
                          style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: Colors.white),
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: IconButton(
                          icon: Image.asset(widget.isFullscreen ? 'assets/images/button_collapse.png' : 'assets/images/button_expand.png'),
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 56,
                  ),
                  Row(
                    children: <Widget>[
                      Expanded(
                        child: Text(
                          'Boligværdi',
                          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          '4.233.123',
                          style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 32,
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                        borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(bottom: 8.0),
                    child: Container(
                      height: 60,
                      decoration: BoxDecoration(
                          color: Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.circular(10.0)
                      ),
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    )
      )
    )
);
返回容器(
键:_键,
//如果我把高度设为500,这里就行了
孩子:InkWell(
onTap:()=>_cardTap(_key,context,house),
孩子:卡片(
形状:圆形矩形边框(
边界半径:边界半径。圆形(16.0),
),
语义容器:对,
clipBehavior:Clip.antiAliasWithSaveLayer,
标高:4,
子:容器(
颜色:颜色,白色,
子:堆栈(
fit:StackFit.expand,
儿童:[
ImageHelper.GetHouseContegoryImage(widget.house.houseContegory),
填充物(
填充:LTRB(12,8,12,8)中的常量边集,
子对象:对齐(
对齐:alignment.topLeft,
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
划船(
儿童:[
扩大(
子:文本(
地址街,
样式:TextStyle(fontSize:26,fontWeight:fontWeight.bold,颜色:Colors.white),
),
),
对齐(
对齐:alignment.centerRight,
孩子:我的钮扣(
图标:Image.asset(widget.isFullscreen?'assets/images/button_collapse.png':'assets/images/button_expand.png'),
),
)
],
),
大小盒子(
身高:56,
),
划船(
儿童:[
扩大(
子:文本(
“Boligværdi”,
样式:TextStyle(fontSize:18,fontWeight:fontWeight.bold,颜色:Colors.white),
),
),
对齐(
对齐:alignment.centerRight,
子:文本(
'4.233.123',
样式:TextStyle(fontSize:18,fontWeight:fontWeight.bold,颜色:Colors.white),
),
)
],
),
大小盒子(
身高:32,
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
),
填充物(
填充:仅限常量边集(底部:8.0),
子:容器(
身高:60,
装饰:盒子装饰(
颜色:颜色(0xFFFFFF),
边界半径:边界半径。圆形(10.0)
),
),
)
],
),
),
)
],
),
)
)
)
);
如何使项目(容器、卡片或问题所在的是列…)达到显示其内容所需的高度

谢谢你

Søren

你能试着用
扩展的
小部件替换
容器
吗?@sudo_kaizen我想你指的是第一个(最上面的)容器。如果我这样做,我会得到一个不同的错误(现在无法测试),我想是因为扩展占据了ListView中的所有高度?这是我的“Stack(fit:StackFit.expand)”问题所在,这个链接让我找到了原因()。现在我有了其他问题,但那是另一回事。这就是dev的做法哈哈