我想在其下方有一个简单的输入字段并带有按钮,我试图将其放在屏幕中央。
这是我的代码:
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}
即使我使用Center()
小部件,它也会到达屏幕顶部。
答案 0 :(得分:1)
您需要的全部是使用mainAxisAlignment
和crossAxisAlignment
来垂直居中
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}