I want to achieve a BottomSheet which adapts in height to its content and contains a short list of horizonal items (max. 20 items).
showModalBottomSheet(
context: context,
builder: (context) {
return SafeArea(
child: Wrap(
children: [
ListTile(title: Text('Foo')),
ListTile(title: Text('Bar')),
Expanded(
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 100,
itemBuilder: (_, index) {
return Card(
child: Padding(
padding: EdgeInsets.all(8),
child: Text("Item $index"),
),
);
},
),
),
],
),
);
},
);
Problem:
No matter what I try, wrapping in Expanded etc., I always get the error Failed assertion... hasSize
.
I would like to achieve a horizontally scrollabe list inside the bottom sheet, like in the picture of the material docs
How is that possible?
Thanks for your help!
2
Answers
You need to wrap your
ListView.builder
inSizedBox
with aheight
.Example:
Add your
ListView
insideSizedBox
orContainer
and give it to specificheight
, becauseExpanded
takes full heightTry below code:
Result with SizedBox