我有一个具有动态内容的ListView,我希望每个项目都根据其内容具有动态高度,但是如果我没有为每个项目都设置一个固定高度,则会出现错误
package:flutter / src / rendering / sliver_multi_box_adaptor.dart':失败的断言:549行pos 12:'child.hasSize':不正确。
这是ListView itemBuilder的完整布局:
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)
),
),
)
],
),
),
)
],
),
)
)
)
);
如何获取物品(容器,卡片或问题列)以达到显示其内容所需的高度?
谢谢
索伦