如何为Flutter容器提供与listview子对象自身内部的高度相等的高度



当我没有给容器一个高度时,我有一个错误,它给了我这个错误:

================呈现库捕获的异常=======================================在paint((过程中引发以下_CastError:在Null值上使用了Null检查运算符

所以为什么我给他高度:200,但它的静态高度我想给容器一个他里面的列表视图大小。

集装箱代码:

Container(
// height:200,
alignment: Alignment.topLeft,
decoration: const BoxDecoration(
border: Border(
// top: BorderSide(color: Colors.black12),
bottom: BorderSide(color: Colors.black12),
)),
padding: const EdgeInsets.fromLTRB(10, 5, 0, 20),
child: Column(
children: <Widget>[
Container(width: 22, color: colors),
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8.0),
itemCount: reposReplay?.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
ListTile(
title: Column(children: [
Padding(
padding:
const EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Row(
children: [
Expanded(
child: Text("${reposReplay?[index].by}",
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 14,
color: Colors.deepOrangeAccent,
fontWeight: FontWeight.bold)),
),
Expanded(
child: Text(time,
textAlign: TextAlign.end,
style: const TextStyle(
fontSize: 14,
color: Colors.deepOrangeAccent,
fontWeight: FontWeight.bold)),
),
],
),
),
]),
subtitle: Text("${reposReplay?[index].text!.replaceAll("&#x27;", "'").replaceAll("&gt;", ">").replaceAll("&quot;", """).replaceAll("&#x2F;", "/").replaceAll("<p>", "n").replaceAll("&gt;.&quot;", ">.").replaceAll(exp, "")}",
textAlign: TextAlign.justify,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal, color: Colors.black)),
),
const Divider(
height: 2.0,
),
],
);
}),
)
],
)
),

在listview.builder中使用以下内容:

physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,

最新更新