Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 BoxConstraints强制无限宽_Flutter_Dart_Flutter Layout_Width - Fatal编程技术网

Flutter BoxConstraints强制无限宽

Flutter BoxConstraints强制无限宽,flutter,dart,flutter-layout,width,Flutter,Dart,Flutter Layout,Width,我在列中添加行时出错。我得到以下错误: I/flutter ( 6449): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ I/flutter ( 6449): The following assertion was thrown during performLayout(): I/flutter ( 6449): BoxConstraint

我在列中添加行时出错。我得到以下错误:

I/flutter ( 6449): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 6449): The following assertion was thrown during performLayout():
I/flutter ( 6449): BoxConstraints forces an infinite width.
I/flutter ( 6449): These invalid constraints were provided to RenderAnimatedOpacity's layout() function 
以下是我的代码供参考:

return new Scaffold(
      backgroundColor: whiteColor,
      body: new Column(
        children: <Widget>[
          imgHeader,
          lblSignUp,
          txtEmail,
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              txtFirstName,
              txtLastName
            ],
          ),
        ],
      ),
    );
返回新脚手架(
背景颜色:白色,
正文:新栏目(
儿童:[
伊姆盖德,
lblSignUp,
txtEmail,
划船(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
txtFirstName,
txtLastName
],
),
],
),
);

如果在
行中使用
文本字段
,则需要使用
灵活
扩展

更多的细节在这里给出了这个答案


错误原因:

TextField
在水平方向上展开,
,因此我们需要限制
TextField
的宽度,有很多方法

  • 使用扩展的

     Row(
      children: <Widget>[
        Expanded(child: TextField()),
        // more widgets
      ],
    )
    
  • 将其包装在
    容器中
    大小框中
    并提供
    宽度

    Row(
      children: <Widget>[
        SizedBox(width: 100, child: TextField()),
        // more widgets
      ],
    )       
    
    行(
    儿童:[
    SizedBox(宽度:100,子项:TextField()),
    //更多小部件
    ],
    )       
    

  • 只有当您试图为
    容器定义一个无限
    宽度
    高度
    时,才会发生这种情况,该容器是要使用所有空间的
    文本字段
    的父级

    要解决此问题,您应该使用
    Flexible
    Expanded
    包装
    文本字段

    这样做是为了解决上面和后面的问题

     Expanded(
       child: txtFirstName,
     ),
    
     Flexible(
       child: txtLastName,
     ),
    
    完整示例

     Column(
        children: <Widget>[
          imgHeader,
          lblSignUp,
          txtEmail,
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Expanded(
                child: txtFirstName,
              ),
              Flexible(
                child: txtLastName,
              ),
            ],
          ),
        ],
      )
    
    列(
    儿童:[
    伊姆盖德,
    lblSignUp,
    txtEmail,
    划船(
    mainAxisAlignment:mainAxisAlignment.start,
    儿童:[
    扩大(
    孩子:txtFirstName,
    ),
    灵活的(
    孩子:txtLastName,
    ),
    ],
    ),
    ],
    )
    
    我有一个ListView,它抛出了这个异常,并将它包装在一个大小框中,设置宽度对我来说很有用!谢谢
     Column(
        children: <Widget>[
          imgHeader,
          lblSignUp,
          txtEmail,
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Expanded(
                child: txtFirstName,
              ),
              Flexible(
                child: txtLastName,
              ),
            ],
          ),
        ],
      )