我在颤振中设计了这种布局。我想将卡移动到中心(水平和垂直)。卡的宽度和高度应为包装内容。
有人知道如何实现这一目标吗?
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)),
)
],
))
],
),
));
}
}
答案 0 :(得分:2)
将crossAxisAlignment
的参数值更改为CrossAxisAlignment.center
,然后添加mainAxisAlignment: MainAxisAlignment.center
和mainAxisSize: MainAxisSize.min
答案 1 :(得分:0)
body: Center(child: Card(...
或
body: Container(alignment: Alignment.center, child: Card(...
通过Container
,您可以使用不同类型的alignment