【问题标题】:Flutter Row main axis alignment not workingFlutter Row主轴对齐不起作用
【发布时间】:2019-06-21 08:51:25
【问题描述】:

我正在尝试将两个材质按钮连续放置,并且它们之间的空间均匀。但 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()


    );
  }

【问题讨论】:

  • 你不应该在行内换行,你只能使用一个 Row()

标签: dart flutter flutter-layout


【解决方案1】:

尝试像这样简化代码:

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

【讨论】:

    猜你喜欢
    • 2021-08-04
    • 2021-08-12
    • 1970-01-01
    • 2019-10-15
    • 2020-11-16
    • 2021-05-14
    • 2016-11-07
    • 2020-03-05
    • 2011-07-28
    相关资源
    最近更新 更多