I\'m using SingleChildScrollView and a Column to display a swiper and a gridview.
If I use some other widget like text, image in my column, the app shows ok. But my
I had exactly the same problem, and for me what worked was to wrap the swiper first with the expanded widget, and then wrap the expanded with the container with the sizes needed 1.Container 2. Expanded 3. Swiper
You cannot have an Expanded
widget within the SingleChildScrollView
which has boundless vertical dimensions.
class _HomePageState extends State<HomePage> {
final List<ListItem> _children;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
child: Container(
height: 200,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return Image.network(
"http://via.placeholder.com/350x150",
fit: BoxFit.fitHeight,
);
},
itemCount: 5,
pagination: SwiperPagination(),
control: SwiperControl(),
),
)),
Expanded(
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, childAspectRatio: 1.0),
itemBuilder: (BuildContext context, int index) {
return ListItemWidget(_children[index]);
},
itemCount: _children.length,
),
),
],
),
);
}
}