[英]Flutter: ModalBottomSheet with ListView.separated() size to content
I'm using ListView.separated()
inside in the builder
of showModalBottomSheet()
.我在
showModalBottomSheet()
的builder
中使用ListView.separated()
) 。 I would like for the BottomSheet
to resize based on the number of ListTile
widgets displayed.我希望
BottomSheet
根据显示的ListTile
小部件的数量调整大小。
Here's my code:这是我的代码:
showModalBottomSheet(
context: context,
backgroundColor: Colors.blueGrey,
isScrollControlled: false,
builder: (context) => Wrap(
children: [
ListView.separated(
itemCount: lists.length,
itemBuilder: (BuildContext context, int index) =>
ListTile(
title: Text(lists[index].listName),
),
separatorBuilder: (BuildContext context, int index) =>
Divider(),
),
],
),
);
I've tried wrapping the ListView
inside a Wrap
widget, but I got an error because the child of Wrap
doesn't have a set height.我尝试将
ListView
包装在Wrap
小部件中,但由于Wrap
的子级没有设置高度,因此出现错误。 Any tips?有小费吗?
You can do this by using the shrinkWrap
parameter in the ListView
widget.您可以通过使用
ListView
小部件中的shrinkWrap
参数来执行此操作。
showModalBottomSheet(
context: context,
builder: (context) => ListView.separated(
shrinkWrap: true,
itemCount: 4,
itemBuilder: (BuildContext context, int index) => ListTile(
title: Text('item $index'),
),
separatorBuilder: (BuildContext context, int index) => Divider(),
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.