I'm using ListView.separated()
inside in the builder
of showModalBottomSheet()
. I would like for the BottomSheet
to resize based on the number of ListTile
widgets displayed.
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. Any tips?
You can do this by using the shrinkWrap
parameter in the ListView
widget.
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(),
),
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.