我試圖在 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);
},
),
),
],
)
uj5u.com熱心網友回復:
您可以shrinkWrap: true,
在 listView 中包含這將解決,
Flexible(
child: ListView.builder(
shrinkWrap: true,
physics: const ScrollPhysics(),
但我更喜歡將專案長度增加一。
ListView.builder(
physics: const ScrollPhysics(),
itemCount: itemLength 1,
itemBuilder: (context, index) {
if (index == itemLength) {
return Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.only(bottom: 11),
child: Text("BTN")),
);
}
return CheckboxListTile(
value: true,
onChanged: (e) {},
title: Text(
"tags[index].name",
),
);
}),
uj5u.com熱心網友回復:
您需要remove the SizedBox height
,shrinkWrap: true
在 ListView.builder 中設定并設定physics : NeverScrollableScrollPhysics()
您的代碼將是
SizedBox(
width: widget.isDialog ? 600 : double.infinity,
child: ThemeConfig.selectFilterAsCheckBox
? Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Flexible(
child: ListView.builder(
shrinkWrap: true
physics: const NeverScrollableScrollPhysics(),
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)
? theme.textTheme.labelMedium?.copyWith(
color: ThemeConfig.colorTertiary)
: theme.textTheme.titleSmall?.copyWith(
color: ThemeConfig.colorTertiary),
),
);
}),
),
Padding(
padding: const EdgeInsets.only(bottom: sdPaddingMedium),
child: SdPrimaryButton(
title: appLocalizations.btnApply,
onPressed: () {
viewModel.setTags(tempSelectedTags);
Navigator.pop(context);
},
),
),
],
)
uj5u.com熱心網友回復:
解決方案是了解 Alertdialog 的作業原理。必須洗掉靈活小部件并且串列必須是可滾動的。這是一個快速的答案。
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Title'),
content: SizedBox(
width: 600,
height: MediaQuery.of(context).size.height / 2.5,
child: ListView.builder(
itemCount: tags.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text(tags[index]),
value: false,
onChanged: (e) {},
);
}),
),
actions: [
ElevatedButton(
child: Text('Apply'),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
)
輸出如下:
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/506380.html
上一篇:Flutter水平和垂直串列視圖