所以我有尝试使用center()小部件的这段代码,但我无法将元素放在中间,这就是它们的外观。
有趣的是,绿色容器占用了整个屏幕宽度,但容器内的小部件未对齐以保持水平居中。
这是代码
Center(
child: Container(
color : Colors.green,
alignment: Alignment(0.0, 0.0),
child: Row(
children: <Widget>[
InkWell(
child: Text(
" Likes \n" + document['likes'].toString()),
onTap: () => LikeQuote(document),
),
InkWell(
child: Text(" Dislikes \n" +
document['dislikes'].toString()),
onTap: () => DislikeQuote(document),
),
InkWell(
child: Text(" Shares \n" +
document['shares'].toString()),
onTap: () => ShareQuote(),
),
],
),
),
),
我希望喜欢和喜欢的人成为中心人物。我该怎么办?
答案 0 :(得分:2)
您应该使用mainAxisAlignment
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[ comp1(), comp2()
答案 1 :(得分:1)
要在“行”或“列”中对齐小部件,可以在“行”或“列”中使用这些参数。
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
行:
列:
答案 2 :(得分:0)
Container(
color : Colors.green,
alignment: Alignment(0.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Text(
" Likes \n" + document['likes'].toString()),
onTap: () => LikeQuote(document),
),
InkWell(
child: Text(" Dislikes \n" +
document['dislikes'].toString()),
onTap: () => DislikeQuote(document),
),
InkWell(
child: Text(" Shares \n" +
document['shares'].toString()),
onTap: () => ShareQuote(),
),
],
)
,
),