Space between Column's children in Flutter

后端 未结 14 815
刺人心
刺人心 2021-02-02 04:33

I have a Column widget with two TextField widgets as children and I want to have some space between both of them.

I already tried mainAxi

14条回答
  •  难免孤独
    2021-02-02 05:14

    There are many ways of doing it, I'm listing a few here.

    1. Use Container and give some height:

      Column(
        children: [
          Widget1(),
          Container(height: 10), // set height
          Widget2(),
        ],
      )
      
    2. Use Spacer

      Column(
        children: [
          Widget1(),
          Spacer(), // use Spacer
          Widget2(),
        ],
      )
      
    3. Use Expanded

      Column(
        children: [
          Widget1(),
          Expanded(child: SizedBox()), // use Expanded
          Widget2(),
        ],
      )
      
    4. Use mainAxisAlignment

      Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround, // mainAxisAlignment
        children: [
          Widget1(),
          Widget2(),
        ],
      )
      
    5. Use Wrap

      Wrap(
        direction: Axis.vertical, // make sure to set this
        spacing: 20, // set your spacing
        children: [
          Widget1(),
          Widget2(),
        ],
      )
      

提交回复
热议问题