I am using wrap to display some images, the direction of Wrap
is set to Axis.horizontal
. When it runs out of horizontal space, it is creating new row. As long as there is enough space vertically, everything is getting displayed as it should. But the moment there are a lot of images, it is giving a Bottom Overflow.
I tried wrapping the Wrap
widget inside SingleChildScrollView
, ListView
and Expanded
but nothing seems to work. Here is my code:
@override
Widget build(BuildContext context) {
return Wrap(
direction: Axis.horizontal,
spacing: 8,
runSpacing: 12,
children: [
_buildImageCard('abc'),
_buildImageCard('def'),
_buildImageCard('ghi'),
_buildImageCard('jkl'),
],
);
}
}
and the _buildImageCard
Widget _buildImageCard(String imagePath) {
return SizedBox(
width: 500,
height: 400,
child: Card(
elevation: 5,
),
);
}
The result is:
All you have to do is set Global Keys for your widgets and call Scrollable. ensureVisible on the key of your widget you want to scroll to. For this to work your ListView should be a finite List of objects. If you are using ListView.
try SingleChildScrollView
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Wrap(
direction: Axis.horizontal,
spacing: 8,
runSpacing: 12,
children: [
_buildImageCard('abc'),
_buildImageCard('def'),
_buildImageCard('ghi'),
_buildImageCard('jkl'),
_buildImageCard('jkl'),
_buildImageCard('jkl'),
_buildImageCard('jkl'),
],
),
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With