PageView.builder giving Horizontal viewport was given unbounded height error
PageView
cannot be the direct child of Column
. Change your column to add an Expanded
between the two, as below:
Column(
children: <Widget>[
Expanded(
child: PageView.builder(),
),
]
)
To explain what's going on here, Column
has an unbounded horizontal width, ie it'll keep expanding horizontally to take as much space as it's child needs. PageView
(and any other horizontally scrolling widget) requires horizontal constraints for the scroll logic to work.
Expanded
restricts the horizontal size of the PageView
by taking up as much space as possible, which should solve the issue.
You can use any Widget that has a fixed height and width to wrap the PageView.
For example, I use Container()
:
Column(
children: <Widget>[
Container(
width: double.infinity,
height: 100.0,
child: PageView.builder(),
),
]
)