flutter - ListView 和 Card Flutter 中的额外“空间”
问题描述
我在我的第一个列表视图项目上有这个“额外空间”,这是一张封装在容器中的卡片。如何删除它?
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(15.0),
height: 300,
child: Column(children: [
Row(children: [
Expanded(
child: Text("Lowest Fuel Price",
style: TextStyle(
fontWeight: FontWeight.w500,
color: Theme.orange3,
fontSize: 16.0)))
]),
Container(
height: 250,
child: Card(
elevation: 3,
child: ListView.builder(
itemCount: cheapest.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
final item = cheapest[index];
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(
item.petrolType,
style: TextStyle(
color: Theme.gray1, fontSize: 18),
),
Text(
"\$" + item.petrolPrice,
style: TextStyle(
color: Theme.gray1, fontSize: 25),
),
Image(
fit: BoxFit.fill,
image: new AssetImage(
'assets/images/fuel_station/' +
item.petrolStation.toLowerCase() +
'.png')),
]),
index != cheapest.length - 1
? Divider(
color: Colors.grey,
)
: Divider(color: Colors.white)
],
);
})),
)
]));
}
解决方案
https://api.flutter.dev/flutter/widgets/ListView-class.html
默认情况下,ListView 将自动填充列表的可滚动末端,以避免 MediaQuery 填充指示的部分障碍。为避免此行为,请使用零填充属性覆盖。
Card(
elevation: 3,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView.builder(),
),
),
推荐阅读
- c# - 使用 MVVM 模式关闭打开的窗口,产生 System.NullReferenceException 错误
- node.js - 如何在nodejs中通过shell运行时等待异步函数
- reactjs - 模块别名无法解析为玩笑(CRA 和 custom-cra)
- kubernetes - Calico 从所有节点通告所有 Kubernetes 节点子网
- python - 如何找到在每次迭代中获得的最大值以将其附加到列表中
- java - Swing 中的 Ctrl + ~ 热键
- python - 如何从 ONNX 模型中获取输入数据?
- windows - 我们可以在一台机器上从 cmake 制作解决方案文件并在另一台机器上运行吗?
- c# - 重新定义一个类或函数
- vba - 您如何转到从列表框中选择并显示在导航表单上的特定记录?