颤振行主轴对齐不起作用

时间:2019-01-28 11:01:14

标签: dart flutter flutter-layout

我正在尝试将两个materialbuttons连续放置,并且它们之间要有均匀的间隔。但是mainAxisAlignment小部件不起作用。这两个按钮在行的开头都相互粘在一起。

Widget _buildSignInButton() {
    return Row(
      children: <Widget>[
        Container(
          child: new Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              new SignInButton(
                onPressed: () {
                  _googleSignIn();
                },
                imageUrl: 'assets/images/glogo.png',
              ),
              new SignInButton(
                onPressed: () {
                  _fbSignIn();
                },
                imageUrl: 'assets/images/fblogo.png',
              ),
            ],
          ),
        )
      ],
    );
  }

 Widget build(BuildContext context) {
    return Container(
        child: _buildSignInButton()


    );
  }

1 个答案:

答案 0 :(得分:0)

尝试简化这样的代码:

Row(
  // children: <Widget>[
  //   new Container(
  //     child: new Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          new Text('123'),
          new Text('456'),
        ],
  //     ),
  //   ),
  // ],
),

或将Container替换为Expanded

Row(
  children: <Widget>[
    new Expanded(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          new Text('123'),
          new Text('456'),
        ],
      ),
    ),
  ],
),

查看文档以获取有关差异的更多详细信息:https://flutter.io/docs/development/ui/layout/box-constraints#flex

相关问题