Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 体型及;NestedScrollView中未考虑边距_Flutter_Nestedscrollview - Fatal编程技术网

Flutter 体型及;NestedScrollView中未考虑边距

Flutter 体型及;NestedScrollView中未考虑边距,flutter,nestedscrollview,Flutter,Nestedscrollview,我试图理解为什么在下面的代码中,以“Containers”(容器)为例,即使容器有约束或大小,也会填充整个空间 return Scaffold( body: SafeArea( child: NestedScrollView( physics: BouncingScrollPhysics(), headerSliverBuilder: (context, innerBoxIsScrolled) {

我试图理解为什么在下面的代码中,以“Containers”(容器)为例,即使容器有约束或大小,也会填充整个空间

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的
滑动条的大小完全相同


为了
容器
保留其大小,请设置父级,该父级将有其自身的约束,例如
中心
堆栈

您可以检查更新答案