【发布时间】:2023-01-31 03:34:00
【问题描述】:
我试图在 listview 生成器之后删除额外的空间,但我没有成功 我尝试了不同的方法,比如我用 MediaQuery.removePadding 包装了我的 listview.builder 并将填充值设置为零 我还将 listview.builder 的填充设置为零同样,但我没有得到所需的输出。我不知道我在哪里犯了错误。
这是代码:
SizedBox(
width: widget.isDialog ? 600 : double.infinity,
height: MediaQuery.of(context).size.height / 2.5,
child: ThemeConfig.selectFilterAsCheckBox
? Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Flexible(
child: ListView.builder(
physics: const ScrollPhysics(),
itemCount: tags.length,
itemBuilder: (context, index) {
return CheckboxListTile(
value: tempSelectedTags.contains(tags[index].id),
onChanged: (e) {
setState(() {
if (tempSelectedTags.contains(tags[index].id)) {
tempSelectedTags.remove(tags[index].id);
} else {
tempSelectedTags.add(tags[index].id);
}
});
},
title: Text(
tags[index].name,
style: !tempSelectedTags.contains(tags[index].id)
? textTheme.labelMedium?.copyWith(
color: ThemeConfig.colorgreen)
: textTheme.titleSmall?.copyWith(
color: ThemeConfig.colorgreen),
),
);
}),
),
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: PrimaryButton(
title: Apply,
onPressed: () {
viewModel.setting(tempSelectedTags);
Navigator.pop(context);
},
),
),
],
)
【问题讨论】:
-
你能简化小部件吗,这里的数据是未知的。
-
我认为问题在于您的 ListView 嵌套在大小恒定为
MediaQuery.of(context).size.height / 2.5的 SizedBox 中。因此,即使 List 中只有一个元素,ListView 仍然会占用比需要更多的空间,而实际上它可能是 SizedBox 填充了所有空白空间。由于上大学的原因,过去两个月我没有使用 Flutter,但我想你可以尝试使用 Container 或 Flexible 或类似的东西来代替 SizedBox。 -
@YeasinSheikh 感谢您的回复。是的,我认为它是一个对话框,当我点击这个弹出窗口的过滤器按钮时,你可以在输出中看到
-
@Samaranth 是的,我需要小型设备的高度,它在 iPhone 等小型设备上工作正常。
-
好吧,你喜欢灵活的高度对话框吗?
标签: flutter dart listview flutter-layout