如何在颤动中对齐卡片视图中心

时间:2019-01-06 08:19:43

标签: android ios flutter

我在颤振中设计了这种布局。我想将卡移动到中心(水平和垂直)。卡的宽度和高度应为包装内容。

有人知道如何实现这一目标吗?

class ContactUsScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("CONTACT US"),
          backgroundColor: Colors.redAccent,
        ),
        body: Card(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                child: Text("Need Help ?",
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        fontSize: 22)),
              ),
              Container(
                margin: EdgeInsets.only(top: 10),
                child: Text("Max MagiX,",
                    style: TextStyle(
                        fontWeight: FontWeight.normal,
                        color: Colors.black,
                        fontSize: 16)),
              ),
              Container(
                child: Text("San Francisco,",
                    style: TextStyle(
                        fontWeight: FontWeight.normal,
                        color: Colors.black,
                        fontSize: 16)),
              ),
              Container(
                child: Text("CA, USA",
                    style: TextStyle(
                        fontWeight: FontWeight.normal,
                        color: Colors.black,
                        fontSize: 16)),
              ),
              Container(
                margin: EdgeInsets.only(top: 10),
                  child: Row(
                children: <Widget>[
                  Icon(Icons.phone),
                  Container(
                    margin: EdgeInsets.only(left: 2),
                    child: Text("+1 8002 8002 82",
                        style: TextStyle(
                            fontWeight: FontWeight.normal,
                            color: Colors.black,
                            fontSize: 16)),
                  )
                ],
              )),
              Container(
                  margin: EdgeInsets.only(top: 10),
                  child: Row(
                    children: <Widget>[
                      Icon(Icons.email),
                      Container(
                        margin: EdgeInsets.only(left: 2),
                        child: Text("hello@xyz.com",
                            style: TextStyle(
                                fontWeight: FontWeight.normal,
                                color: Colors.black,
                                fontSize: 16)),
                      )
                    ],
                  ))
            ],
          ),
        ));
  }
}

enter image description here

2 个答案:

答案 0 :(得分:2)

crossAxisAlignment的参数值更改为CrossAxisAlignment.center,然后添加mainAxisAlignment: MainAxisAlignment.centermainAxisSize: MainAxisSize.min

答案 1 :(得分:0)

body: Center(child: Card(...

body: Container(alignment: Alignment.center, child: Card(...

通过Container,您可以使用不同类型的alignment