BoxConstraints forces an infinite width

前端 未结 3 1244
無奈伤痛
無奈伤痛 2020-12-15 16:49

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

I/flutter ( 6449): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═══════════════         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-15 17:12

    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: [
          Expanded(child: TextField()),
          // more widgets
        ],
      )
      
    2. Use Flexible

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

      Row(
        children: [
          SizedBox(width: 100, child: TextField()),
          // more widgets
        ],
      )       
      

提交回复
热议问题