我试图将两个项目的极端对齐,一个在左边,另一个在右边。我有一排在左边对齐,然后该行的一个孩子在右边对齐。但是,似乎子行正在从其父行获取alignment属性。这是我的代码
var SettingsRow = new Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: <Widget>[ Text("Right",softWrap: true,), ], ); var nameRow = new Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: <Widget>[ Text("Left"), SettingsRow, ], );
结果我得到这样的东西
Left Right
我想要的是
行上也有足够的空间。我的问题是为什么孩子Row不能展示其MainAxisAlignment.end财产?
MainAxisAlignment.end
Row改为使用一个mainAxisAlignment: MainAxisAlignment.spaceBetween。
Row
mainAxisAlignment: MainAxisAlignment.spaceBetween
new Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Text("left"), new Text("right") ] );
或者你可以使用 Expanded
Expanded
new Row( children: [ new Text("left"), new Expanded( child: settingsRow, ), ], );