Set column width in flutter

前端 未结 2 541
忘掉有多难
忘掉有多难 2021-01-30 16:15

I need to set a Column width in flutter, I have to do a layout with 3 sections, one should be 20% of the screen, the other one 60% and the last one 20%. I know that those 3 colu

2条回答
  •  野的像风
    2021-01-30 16:43

    Limiting the width of a Column could be

    1. Limiting the width of Column itself, use SizedBox

      SizedBox(
        width: 100, // set this
        child: Column(...),
      )
      

    2 (A). Limiting width of children inside Column, without hardcoding values

    Row(
      children: [
        Expanded(
          flex: 3, // takes 30% of available width 
          child: Child1(),
        ),
        Expanded(
          flex: 7, // takes 70% of available width  
          child: Child2(),
        ),
      ],
    )
    

    2 (B). Limiting width of children inside Column, with hardcoding values.

    Row(
      children: [
        SizedBox(
          width: 100, // hard coding child width
          child: Child1(),
        ),
        SizedBox(
          width: 200, // hard coding child width
          child: Child2(),
        ),
      ],
    )
    

提交回复
热议问题