如何限制AlertDialog的高度 [英] How to constrain height of AlertDialog
本文介绍了如何限制AlertDialog的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我显示其中带有列表的对话框.
I show dialog with list inside it.
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(select_conference),
content: ListView.separated(
itemCount: selected.length,
separatorBuilder: (context, index) => CommonDivider(),
itemBuilder: (context, index) => ListTile(...),
),
);
});
但是无论有多少元素-对话框都会填充所有可用高度.有什么解决方案可以解决此问题,而无需计算列表元素的高度?
But no matter how many elements is has - dialog fills all available height. Is there any solution to solve this without calculating height of list elements?
推荐答案
您可以将其包装在SizedBox
或ConstrainedBox
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 100.0),
child: AlertDialog(
...
),
);
或者,您可以在ListView
中将shrinkWrap
设置为true
,以使其占用的垂直空间最少.
Alternatively, you can set shrinkWrap
to true
in your ListView
so that it takes the least amount of vertical space necessary.
ListView(
shrinkWrap: true,
...
)
这篇关于如何限制AlertDialog的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文