如何将小部件放在行内?

时间:2019-08-23 10:29:54

标签: android flutter

所以我有尝试使用center()小部件的这段代码,但我无法将元素放在中间,这就是它们的外观。 here's the snip

有趣的是,绿色容器占用了整个屏幕宽度,但容器内的小部件未对齐以保持水平居中。

这是代码

    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(),
                    ),
                ],
            ),
        ),
    ),

我希望喜欢和喜欢的人成为中心人物。我该怎么办?

3 个答案:

答案 0 :(得分:2)

您应该使用mainAxisAlignment

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children:[ comp1(), comp2()

答案 1 :(得分:1)

要在“行”或“列”中对齐小部件,可以在“行”或“列”中使用这些参数。

  mainAxisAlignment: MainAxisAlignment.center,              
  crossAxisAlignment: CrossAxisAlignment.center,

行:

  • mainAxisAlignment确定水平对齐路径
  • crossAxisAlignment确定垂直对齐路径

列:

  • mainAxisAlignment确定垂直对齐路径
  • crossAxisAlignment确定水平对齐路径

答案 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(),
              ),
            ],
          )
          ,
        ),