Flutter 体型及;NestedScrollView中未考虑边距
我试图理解为什么在下面的代码中,以“Containers”(容器)为例,即使容器有约束或大小,也会填充整个空间Flutter 体型及;NestedScrollView中未考虑边距,flutter,nestedscrollview,Flutter,Nestedscrollview,我试图理解为什么在下面的代码中,以“Containers”(容器)为例,即使容器有约束或大小,也会填充整个空间 return Scaffold( body: SafeArea( child: NestedScrollView( physics: BouncingScrollPhysics(), headerSliverBuilder: (context, innerBoxIsScrolled) {
return Scaffold(
body: SafeArea(
child: NestedScrollView(
physics: BouncingScrollPhysics(),
headerSliverBuilder: (context, innerBoxIsScrolled) {
return <Widget>[];
},
body: Container(
constraints: BoxConstraints(
maxHeight: 100,
minWidth: 100,
),
color: Colors.red,
height: 100,
width: 100,
child: Container(
constraints: BoxConstraints(
maxHeight: 50,
minWidth: 50,
),
color: Colors.yellow,
height: 50,
width: 50,
child: Text('a'),
),
),
),
),
);
返回脚手架(
正文:安全区(
子:嵌套滚动视图(
物理:弹跳CrollPhysics(),
headerSliverBuilder:(上下文,InnerBoxIsCrowled){
返回[];
},
主体:容器(
约束:BoxConstraints(
最大高度:100,
最小宽度:100,
),
颜色:颜色,红色,
身高:100,
宽度:100,
子:容器(
约束:BoxConstraints(
最大高度:50,
最小宽度:50,
),
颜色:颜色,黄色,
身高:50,
宽度:50,
child:Text('a'),
),
),
),
),
);
您可以在整个页面上添加列
,以控制每个容器的大小
您可以尝试以下方法:
return Scaffold(
body: SafeArea(
child: NestedScrollView(
physics: BouncingScrollPhysics(),
headerSliverBuilder: (context, innerBoxIsScrolled) {
return <Widget>[];
},
body: Column(
children: [
Container(
color: Colors.red,
height: 100,
width: 100,
child: Container(
margin: EdgeInsets.all(25.0),
color: Colors.yellow,
height: 50,
width: 50,
child: Text('a'),
),
),
],
),
),
),
);
返回脚手架(
正文:安全区(
子:嵌套滚动视图(
物理:弹跳CrollPhysics(),
headerSliverBuilder:(上下文,InnerBoxIsCrowled){
返回[];
},
正文:专栏(
儿童:[
容器(
颜色:颜色,红色,
身高:100,
宽度:100,
子:容器(
边距:所有边缘集(25.0),
颜色:颜色,黄色,
身高:50,
宽度:50,
child:Text('a'),
),
),
],
),
),
),
);
如果一个子项需要与其父项不同的大小,而父项没有足够的信息将其对齐,则该子项的大小可能会被忽略。定义路线时要具体
这里,您有第一个容器想要有它的大小,但是它们被忽略了,因为屏幕强制它与屏幕减去您可能传递给headerSliverBuilder的滑动条的大小完全相同
为了容器
保留其大小,请设置父级,该父级将有其自身的约束,例如中心
,列
,堆栈
等您可以检查更新答案