Flutter Row 主轴对齐不起作用
Flutter Row main axis alignment not working
我试图将两个材料按钮排成一行,中间甚至 space。但是 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
我试图将两个材料按钮排成一行,中间甚至 space。但是 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