Basically I'm trying to implement a PageView, as I understand I must define a height in the parent of thePageView to work. In the gif you can see that if I don't define the height an error appears in its parent, but if I define a height the error disappears.
The Text("hola") elements in my actual code will be dynamically generated, so I can't define a fixed height. In fact you can see that if I put a height, another error appears because the height of the content of the PageView is greater than what I defined. (MediaQuery.of(context).size.height)
How can i solve this problem?
this is my code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
print("main");
return MaterialApp(title: 'Provider Example', initialRoute: '/', routes: {
'/': (context) => Home(),
'home': (context) => Home(),
});
}
}
class Home extends StatelessWidget {
Home() {
print("home");
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('home'),
),
body: Stack(overflow: Overflow.visible, children: <Widget>[
Positioned.fill(
top: 40,
child: Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Text("text1"),
Text("text2",
style: Theme.of(context).textTheme.bodyText2),
Container(
height: MediaQuery.of(context).size.height,
margin: EdgeInsets.symmetric(
vertical: 50, horizontal: 20),
child: PageView(
physics: NeverScrollableScrollPhysics(),
children: [
Container(
color: Colors.yellow,
child: Column(
children: <Widget>[
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
Text("hola"),
],
),
),
Container(color: Colors.blue)
])),
],
),
),
)),
]));
}
}
