I’m trying to make the pageview be auto height based on its child since the content in child is dynamic. So, the fixed height is not a solution for me.
ListView(
children: [
Container(
//height: 300, //i dont want the fixed height
decoration: BoxDecoration(color: Colors.amber),
child: PageView(
children: [
Text(
"1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1"), //this would be a dynamic content //this would be a dynamic content
Text(
"1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1") //this would be a dynamic content //this would be a dynamic content
],
),
)
],
)
2
Answers
You can wrap the widget with
AspectRatio
.Code Exemple:
The LayoutBuilder widget is used to get the maximum height of its parent widget, which is the ListView in this case. The SizedBox is then given a height equal to the maximum height of the ListView, ensuring that the PageView can take up the maximum available height without causing an infinite height constraint.