【问题标题】:Flutter Row Not Aligning to the Left颤振行未与左侧对齐
【发布时间】:2019-04-09 11:35:43
【问题描述】:

我无法将行与列左侧的文本对齐。

布局如下所示:

但是,我希望用户名(“Peter Jonathan”)和用户句柄(“@pj”)与最左侧对齐。关于如何做到这一点的任何建议?

这是我目前的代码:

class ProfilePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        elevation: 0.0,
//        title: Text('Profile'),
      ),
      body: new Container(
        padding: EdgeInsets.fromLTRB(25.0, 0.0, 25.0, 10.0),
        child: new Column(
          children: <Widget>[
            new Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                new Container(
                  width: 100.0,
                  height: 100.0,
                  child: new Center(
                    child: new Text(
                      "PJ",
                      style: new TextStyle(fontSize: 40.0),
                    ),
                  ),
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    border: new Border.all(color: Colors.purple),
                  ),
                ),
                new Column(
                  children: <Widget>[
                    new Row(
                      children: <Widget>[
                        new Padding(
                          padding: EdgeInsets.all(10.0),
                          child: new Column(
                            children: <Widget>[
                              new Text(
                                '100',
                                style: new TextStyle(fontSize: 20.0),
                              ),
                              new Text('Followers'),
                            ],
                          ),
                        ),

                        new Padding(
                          padding: EdgeInsets.all(10.0),
                          child: new Column(
                            children: <Widget>[
                              new Text(
                                  '100',
                                style: new TextStyle(fontSize: 20.0),
                              ),
                              new Text('Following'),
                            ],
                          ),
                        ),
                      ],
                    ),
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        new Text("Peter Jonathan",
                          style: new TextStyle(
                            fontSize: 18.0,
                            fontWeight: FontWeight.bold,
                          ),
                          textAlign: TextAlign.left,
                        ),
                      ],
                    ),
                    new Row(
                      children: <Widget>[
                        new Text("@pj",
                          style: new TextStyle(
                            fontSize: 18.0,
                            fontStyle: FontStyle.italic,
                            color: Color.fromRGBO(155, 155, 155, 1.0),
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

我听说使用灵活是关键,但是当我这样做时,它无法正确编译。我需要将名称和句柄包装在容器中吗?

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    在第二列下的代码中:添加 - crossAxisAlignment: CrossAxisAlignment.start,

    new Column(
               crossAxisAlignment: CrossAxisAlignment.start,
               children: <Widget>[],
    ....
    

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 2021-08-20
      • 2023-01-16
      • 1970-01-01
      • 2016-01-04
      • 2012-01-24
      • 2013-02-06
      • 2016-07-11
      • 2015-03-22
      相关资源
      最近更新 更多