I was creating bottomScrollSheet with some buttons in it. When i added GridVieb.builder to add list of widgets terminal returned an error:
Vertical viewport was given unbounded height.
and
RenderBox was not laid out: RenderViewport#82680 NEEDS-LAYOUT
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
‘package:flutter/src/rendering/box.dart’: Failed assertion: line 1972
pos 12: ‘hasSize’
I added shrinkWrap but it didn’t help.
Code:
GestureDetector(
onTap: () {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return SizedBox(
child: Column(
children: [
Row(
children: [
IconButton(
onPressed: () {},
icon: Image.asset('assets/icons/x.png'),
),
const SizedBox(width: 100),
const Text(
'Categories',
style: AppTextStyles.style16w600,
),
],
),
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),
shrinkWrap: true,
itemBuilder: (context, index) {
// return CategoryWidget();
return Container(
height: 100,
child: Text('hoi'),
);
})
],
),
);
});
},
2
Answers
Try to add
mainAxisSize: MainAxisSize.min
to your column like this:Although your GridView sets
shrinkWrap: true
, your Column tries to take infinite amount of hight space. This does not work in a ScrollView (BottomScrollSheet).MainAxsisSize.min
just takes the space it needsYour code is almost correct, the few things you need to do left is to wrap the top column with a
SingleChildScrollView
and set a fixed height for theGridView.builder
.I made a few tweaks from the snippet you provided. You can modify it accordingly.