69

I am getting an error when I add a row in a column. I am getting the following error:

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 

Also for reference here is my code:

return new Scaffold(
      backgroundColor: whiteColor,
      body: new Column(
        children: <Widget>[
          imgHeader,
          lblSignUp,
          txtEmail,
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              txtFirstName,
              txtLastName
            ],
          ),
        ],
      ),
    );
Code Hunter
  • 10,075
  • 23
  • 72
  • 102

3 Answers3

97

If you are using TextField Inside a Row then you need to use Flexible or Expanded.

More details are given here in this answer.

https://stackoverflow.com/a/45990477/4652688

vipin agrahari
  • 2,691
  • 3
  • 21
  • 31
61

Reason for the error:

TextField expands in horizontal direction and so does the Row, so we need to constrain the width of the TextField, there are many ways of doing it.

  1. Use Expanded

     Row(
      children: <Widget>[
        Expanded(child: TextField()),
        // more widgets
      ],
    )
    
  2. Use Flexible

    Row(
      children: <Widget>[
        Flexible(child: TextField()),
        // more widgets
      ],
    )
    
  3. Wrap it in Container or SizedBox and provide width

    Row(
      children: <Widget>[
        SizedBox(width: 100, child: TextField()),
        // more widgets
      ],
    )       
    
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0

I got this error when using a Positioned widget along the lines of:

Positioned(
  left: _left,
  child: MyWidget(...)
)

And solved by adding the bottom and top arguments, e.g.:

Positioned(
  left: _left,
  bottom: 0,
  top: 0,
  child: MyWidget(...)
)
asherbret
  • 5,439
  • 4
  • 38
  • 58