Set the space between Elements in Row Flutter

后端 未结 8 519
清酒与你
清酒与你 2021-01-30 06:20

Code:

new Container(
          alignment: FractionalOffset.center,
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
             


        
8条回答
  •  无人共我
    2021-01-30 07:02

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

    1. Use SizedBox if you want to set some specific space

      Row(
        children: [
          Text("1"),
          SizedBox(width: 50), // give it width
          Text("2"),
        ],
      )
      


    1. Use Spacer if you want both to be as far apart as possible.

      Row(
        children: [
          Text("1"),
          Spacer(), // use Spacer
          Text("2"),
        ],
      )
      


    1. Use mainAxisAlignment according to your needs:

      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly, // use whichever suits your need
        children: [
          Text("1"),
          Text("2"),
        ],
      )
      


    1. Use Wrap instead of Row and give some spacing

      Wrap(
        spacing: 100, // set spacing here
        children: [
          Text("1"),
          Text("2"),
        ],
      )
      


    1. Use Wrap instead of Row and give it alignment

      Wrap(
        alignment: WrapAlignment.spaceAround, // set your alignment
        children: [
          Text("1"),
          Text("2"),
        ],
      )
      

提交回复
热议问题