代码之家  ›  专栏  ›  技术社区  ›  Sachin Soma

飘动中柱子子体间的空间

  •  12
  • Sachin Soma  · 技术社区  · 8 年前

    Column TextField 小时候的小部件,我想在它们之间有一些空间。

    我已经试过了 mainAxisAlignment: MainAxisAlignment.spaceAround

    3 回复  |  直到 7 年前
        1
  •  189
  •   Viren V Varasadiya    6 年前

    你可以用 Padding 小部件位于这两个小部件之间,或者用 小装置。

    SizedBox

    前任:

    Column(
      children: <Widget>[
        Widget1(),
        SizedBox(height: 10),
        Widget2(),
      ],
    ),
    
        2
  •  150
  •   Marcel    7 年前

    你可以放一个 SizedBox 有特定的 height

    Column(
      children: <Widget>[
        FirstWidget(),
        SizedBox(height: 100),
        SecondWidget(),
      ],
    ),
    

    为什么更喜欢这种方式而不是包装小部件 Padding ? 可读性!有更少的视觉样板,更少的缩进和代码遵循典型的阅读顺序。

        3
  •  69
  •   Nicolás Carrasco-Stevenson ISURU    6 年前

    Wrap() Column() 在子窗口小部件之间添加空格。并使用spacing属性在子窗口小部件之间提供相等的间距

    Wrap(
      spacing: 20, // to apply margin in the main axis of the wrap
      runSpacing: 20, // to apply margin in the cross axis of the wrap
      children: <Widget>[
         Text('child 1'),
         Text('child 2')
      ]
    )
    
        4
  •  32
  •   dmarquina    7 年前

    用填充物把它包装成这样:

    Column(
      children: <Widget>[
      Padding(
        padding: EdgeInsets.all(8.0),
        child: Text('Hello World!'),
      ),
      Padding(
        padding: EdgeInsets.all(8.0),
        child: Text('Hello World2!'),
      )
    ]);
    

    您也可以使用容器(padding…)或SizeBox(height:x.x)。最后一个是最常见的,但它将取决于你想如何管理你的小部件的空间,我喜欢使用填充,如果空间确实是小部件的一部分,并使用sizebox的列表为例。

        5
  •  24
  •   CopsOnRoad    7 年前

    1. 使用 Container 给点高度:

      Column(
        children: <Widget>[
          Widget1(),
          Container(height: 10), // set height
          Widget2(),
        ],
      )
      
    2. 使用 Spacer

      Column(
        children: <Widget>[
          Widget1(),
          Spacer(), // use Spacer
          Widget2(),
        ],
      )
      
    3. 使用 Expanded

      Column(
        children: <Widget>[
          Widget1(),
          Expanded(child: SizedBox()), // use Expanded
          Widget2(),
        ],
      )
      
    4. 使用 mainAxisAlignment

      Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround, // mainAxisAlignment
        children: <Widget>[
          Widget1(),
          Widget2(),
        ],
      )
      
    5. 使用 Wrap

      Wrap(
        direction: Axis.vertical, // make sure to set this
        spacing: 20, // set your spacing
        children: <Widget>[
          Widget1(),
          Widget2(),
        ],
      )
      
        6
  •  8
  •   Bolling    7 年前
    Column(
      children: <Widget>[
        FirstWidget(),
        Spacer(),
        SecondWidget(),
      ]
    )
    

    Spacer创建了一个灵活的空间来插入[flexible]小部件((如专栏)

        7
  •  6
  •   Al-Ameen    7 年前

    与SizedBox的用法相同 above

    Column(
      children: <Widget>[
        FirstWidget(),
        Padding(padding: EdgeInsets.only(top: 40.0)),
        SecondWidget(),
      ]
    )
    
        8
  •  4
  •   eeqk    5 年前

    您也可以用 Padding 使用 map :

    Column(
          children: [Text('child 1'), Text('child 2')]
              .map(
                (e) => Padding(
                  padding: const EdgeInsets.all(8),
                  child: e,
                ),
              )
              .toList(),
        );
    
        9
  •  2
  •   Md.Tarikul Islam suhas sasuke    7 年前

    如果你使用 行/列 那你得用 主轴对齐:

    如果你使用 包裹 行距:5,行距:

    在任何你可以使用的地方 SizeBox()

        10
  •  2
  •   Ali Esfandiari    6 年前

    您可以将列包装到容器中,并将特定高度添加到容器中。 然后您可以使用以下内容:

    Container(
       width: double.infinity,//Your desire Width
       height: height,//Your desire Height
       child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
             Text('One'),
             Text('Two')
          ],
       ),
    ),
    
        11
  •  1
  •   Jitesh Mohite    6 年前

    1.立柱

     Column(
              children: <Widget>[
                Text('Widget A'), //Can be any widget
                SizedBox(height: 20,), //height is space betweeen your top and bottom widget
                Text('Widget B'), //Can be any widget
              ],
            ),
    

         Wrap(
              direction: Axis.vertical, // We have to declare Axis.vertical, otherwise by default widget are drawn in horizontal order
                spacing: 20, // Add spacing one time which is same for all other widgets in the children list
                children: <Widget>[
                  Text('Widget A'), // Can be any widget
                  Text('Widget B'), // Can be any widget
                ]
            )
    
        12
  •  0
  •   Bhargav Sejpal    7 年前
    Column(children: <Widget>[
       Container(margin: EdgeInsets.only(top:12, child: yourWidget)),
       Container(margin: EdgeInsets.only(top:12, child: yourWidget))
    ]);
    
        13
  •  0
  •   Issa    6 年前

    您可能需要在列的子级之间使用SizedBox()小部件。

        14
  •  0
  •   refik    6 年前

    也可以使用助手函数在每个子对象之后添加间距。

    List<Widget> childrenWithSpacing({
      @required List<Widget> children,
      double spacing = 8,
    }) {
      final space = Container(width: spacing, height: spacing);
      return children.expand((widget) => [widget, space]).toList();
    }
    

    Column(
      children: childrenWithSpacing(
        spacing: 14,
        children: [
          Text('This becomes a text with an adjacent spacing'),
          if (true == true) Text('Also, makes it easy to add conditional widgets'),
        ],
      ),
    );
    

    我不确定,如果它是错误的或有一个性能惩罚运行通过一个帮助函数的孩子们为同一个目标?

        15
  •  -1
  •   Mendax    6 年前

    body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Expanded(
               child: Container(
                margin: EdgeInsets.all(15.0),
                decoration: BoxDecoration(
                  color: Color(0xFF1D1E33),
                  borderRadius: BorderRadius.circular(10.0),
                ),
              ),
            ),
            Expanded(
               child: Container(
                margin: EdgeInsets.all(15.0),
                decoration: BoxDecoration(
                  color: Color(0xFF1D1E33),
                  borderRadius: BorderRadius.circular(10.0),
                ),
              ),
            ),
            Expanded(
               child: Container(
                margin: EdgeInsets.all(15.0),
                decoration: BoxDecoration(
                  color: Color(0xFF1D1E33),
                  borderRadius: BorderRadius.circular(10.0),
                ),
              ),
            ),
          ],
         )