Flutter : Vertically center column

后端 未结 9 559
失恋的感觉
失恋的感觉 2020-12-13 23:02

How to vertically center a column in Flutter? I have used widget \"new Center\". I have used widget \"new Center\", but it does not vertically center my column ? Any ideas w

相关标签:
9条回答
  • 2020-12-13 23:37

    Solution as proposed by Aziz would be:

    Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children:children,
    )
    

    It would not be in the exact center because of padding:

    padding: new EdgeInsets.all(25.0),
    

    To make exactly center Column - at least in this case - you would need to remove padding.

    0 讨论(0)
  • 2020-12-13 23:39

    You control how a row or column aligns its children using the mainAxisAlignment and crossAxisAlignment properties. For a row, the main axis runs horizontally and the cross axis runs vertically. For a column, the main axis runs vertically and the cross axis runs horizontally.

     mainAxisAlignment: MainAxisAlignment.center,
     crossAxisAlignment: CrossAxisAlignment.center,
    
    0 讨论(0)
  • 2020-12-13 23:42

    While using Column, use this inside the column widget :

    mainAxisAlignment: MainAxisAlignment.center

    It align its children(s) to the center of its parent Space is its main axis i.e. vertically

    or, wrap the column with a Center widget:

    Center(
      child: Column(
        children: <ListOfWidgets>,
      ),
    )
    

    if it doesn't resolve the issue wrap the parent container with a Expanded widget..

    Expanded(
       child:Container(
         child: Column(
           mainAxisAlignment: MainAxisAlignment.center,
           children: children,
         ),
       ),
    )
    
    0 讨论(0)
提交回复
热议问题