How do I put a flutter PageView inside a Column or Row? I get the error below when I do
In your specific case, I would simply suggest removing the wrapping Column
, as it only has a single child widget.
Anyway, to solve this problem without touching the wrapping Column
you can surround your PageView
with an Expanded or Flexible Widget. The PageView
has an unknown height, because the height of it depends on its children. Therefore it can't be placed in a Column without wrapping it in one of the above widgets.
Would also suggest doing something like this. If remaining children are not wrapped in the Expanded/Flexible with high flex number, Expanded with PageView is gonna take as much space as it can.
Column(
children: <Widget>[
Expanded(
flex: 1,
child: PageView(children: <Widget>[
Text('Page 1'),
Text('Page 2'),
Text('Page 3'),
]),
),
Expanded(child: Text("Test"), flex: 10), #<- add this if you don't want it to be at the bottom of the page
]),