How to centred column and row item in Flutter?

橙三吉。 提交于 2020-01-01 04:07:28

问题


I have small currency table. I didn't use grid. I use Column and rows. Problem is that items in rows is not showing in centre as shown below excel example. What widget do I have to use to makes the items centred? Any help please?

The Example codes:
return new Center(
  child: new Column(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: <Widget>[
      new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
            child: new Icon(
              Icons.crop_rotate,
              color: Colors.white,
            ),
          ),
          new Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
            child: new Text("STG", style: mainHeadTextStyle),
          ),
          new Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
            child: new Text("EUR", style: mainHeadTextStyle),
          ),
          new Padding(
            padding: const EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
            child: new Text("USD", style: mainHeadTextStyle),
          ),
        ],
      ),
      new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
....
....
....

回答1:


If you want the whole table to be Centered, use the mainAxisAlignment property of Column.

Column

mainAxisAlignment: MainAxisAlignment.center => Center Column contents vertically,
crossAxisAlignment: CrossAxisAlignment.center => Center Column contents horizontally,

Row

mainAxisAlignment: MainAxisAlignment.center => Center Row contents horizontally,
crossAxisAlignment: CrossAxisAlignment.center => Center Row contents vertically,



回答2:


If you want it to be like in the picture, use

mainAxisAlignment: MainAxisAlignment.spaceEvenly


来源:https://stackoverflow.com/questions/50871033/how-to-centred-column-and-row-item-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!