Dart 如何使用SingleChildScrollView使堆栈布局可滚动?
我试图使用SingleChildScrollView使堆栈布局可滚动,但它不滚动。这里是否应该使用SingleChildScrollView 我想我已经给出了足够的描述,让每个人都能理解我的问题。这里有更多的文字来满足StackOverflow提出问题的要求。很抱歉 下面是示例代码Dart 如何使用SingleChildScrollView使堆栈布局可滚动?,dart,flutter,flutter-layout,Dart,Flutter,Flutter Layout,我试图使用SingleChildScrollView使堆栈布局可滚动,但它不滚动。这里是否应该使用SingleChildScrollView 我想我已经给出了足够的描述,让每个人都能理解我的问题。这里有更多的文字来满足StackOverflow提出问题的要求。很抱歉 下面是示例代码 @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child:
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: Center(
child: LayoutBuilder(
builder:
(BuildContext context, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Container(
// A fixed-height child.
color: Colors.white,
height: 120.0,
),
Expanded(
// A flexible child that will grow to fit the viewport but
// still be at least as big as necessary to fit its contents.
child: Container(
color: Colors.blue,
//height: 120.0,
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
color: Colors.red[100],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 50,
left: 0,
right: 0,
child: Container(
color: Colors.red[200],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 100,
left: 0,
right: 0,
child: Container(
color: Colors.red[300],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 150,
left: 0,
right: 0,
child: Container(
color: Colors.green[100],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 200,
left: 0,
right: 0,
child: Container(
color: Colors.green[200],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 250,
left: 0,
right: 0,
child: Container(
color: Colors.green[300],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 300,
left: 0,
right: 0,
child: Container(
color: Colors.yellow[100],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 350,
left: 0,
right: 0,
child: Container(
color: Colors.yellow[200],
child: SizedBox(
height: 300,
),
),
),
Positioned(
top: 400,
left: 0,
right: 0,
child: Container(
color: Colors.yellow[300],
child: SizedBox(
height: 300,
),
),
),
],
),
),
),
],
),
),
),
);
},
),
),
),
),
);
}
@覆盖
小部件构建(构建上下文){
返回脚手架(
正文:安全区(
子:容器(
儿童:中心(
子:布局生成器(
建设者:
(BuildContext上下文,BoxConstraints视口Constraints){
返回SingleChildScrollView(
子:约束框(
约束:BoxConstraints(
minHeight:viewportConstraints.maxHeight,
),
孩子:内在的(
子:列(
儿童:[
容器(
//固定身高的孩子。
颜色:颜色,白色,
身高:120.0,
),
扩大(
//一个灵活的子对象,它将增长以适应视口,但
//仍然至少要尽可能大,以适应其内容。
子:容器(
颜色:颜色,蓝色,
//身高:120.0,
子:堆栈(
儿童:[
定位(
排名:0,
左:0,,
右:0,,
子:容器(
颜色:颜色。红色[100],
孩子:大小盒子(
身高:300,
),
),
),
定位(
前50名,
左:0,,
右:0,,
子:容器(
颜色:颜色。红色[200],
孩子:大小盒子(
身高:300,
),
),
),
定位(
前100名,
左:0,,
右:0,,
子:容器(
颜色:颜色。红色[300],
孩子:大小盒子(
身高:300,
),
),
),
定位(
排名:150,
左:0,,
右:0,,
子:容器(
颜色:颜色。绿色[100],
孩子:大小盒子(
身高:300,
),
),
),
定位(
前200名,
左:0,,
右:0,,
子:容器(
颜色:颜色。绿色[200],
孩子:大小盒子(
身高:300,
),
),
),
定位(
排名:250,
左:0,,
右:0,,
子:容器(
颜色:颜色。绿色[300],
孩子:大小盒子(
身高:300,
),
),
),
定位(
排名:300,
左:0,,
右:0,,
子:容器(
颜色:颜色。黄色[100],
孩子:大小盒子(
身高:300,
),
),
),
定位(
top:350,
左:0,,
右:0,,
子:容器(
颜色:颜色。黄色[200],
孩子:大小盒子(
身高:300,
),
),
),
定位(
前400名,
SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
height: 5000,
),
Positioned(
top: 100,
left: 100,
width: 1000,
height: 1000,
child: Container(color: Colors.red),
)
],
),
)
SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
height: 500,
),
Positioned(
top: 100,
left: 100,
child: Container(color: Colors.red, height: 1000, width: 1000),
)
],
),
)
SingleChildScrollView(
child: Stack(
children: <Widget>[
Container(
height: 500,
),
Container(margin: EdgeInsets.only(top: 100, left: 100, color: Colors.red, height: 1000, width: 1000),
],
),
)
Positioned(
top: 20.0,
left: 20.0,
right: 0.0,
bottom: 0.0,
child: SizedBox(
//what ever code is)),
)
)