我试图将两个 Material 按钮排成一行,并且它们之间的间距均匀。但 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(
// 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
关于dart - Flutter Row 主轴对齐不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54400525/