FLUTTER | 对齐不工作

Mus*_*man 10 flutter flutter-layout

尝试将容器与文本视图子对齐,它有一个行父对象在另一列内,尝试了Stack Overflow的多个解决方案,但没有用.

///Transactions Heading
        new Column(
         children: <Widget>[
            new Row(
              children: <Widget>[
                new Container(
                  alignment: Alignment.centerLeft,
                  margin: new EdgeInsets.only(top: 20.0, left: 10.0),
                  child: new Text(
                    "Transactions",
                    style: new TextStyle(
                      color: primaryTextColor,
                      fontSize: 25.0,
                      fontWeight: FontWeight.w700,
                      letterSpacing: 0.1,
                    ),
                  ),
                ),
                new Container(
                  margin: new EdgeInsets.only(top: 25.0),
                  child: new Text(
                    currentGoalTransactions.length.toString() + " items",
                    style: new TextStyle(
                        color: darkHeadingsTextColor, fontSize: 15.0),
                  ),
                ),
              ],
            ),
       ]);
Run Code Online (Sandbox Code Playgroud)

想要将2项文本对齐到右侧

截图

Vin*_*mar 27

mainAxisAlignmentRow小部件中使用该属性.

new Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween, 
    ...
)
Run Code Online (Sandbox Code Playgroud)


jit*_*555 8

使用Spacer它将获得剩余空间并平均分配小部件

     Row(
        children: <Widget>[
          Text("Text 1", style: TextStyle(fontSize: 20),),
          Spacer(),
          Text("Text 2", style: TextStyle(fontSize: 20),),
          Spacer(),
          Text("Text 3", style: TextStyle(fontSize: 20),),
        ],
      ),
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述